コード例 #1
0
def query_area(point):
    # point='36.589 -1.25435'

    try:
        data = {}
       
        query1 = select([Soil], func.ST_Contains(Soil.wkb_geometry, func.ST_Transform(func.ST_GeomFromText(f'POINT({point})', 4326), 4326)))
        result = conn.execute(query1)
        
        for row in result:
            data['pH'] =str(row.phaq)
            data['drainage_desc'] = str(row.sdra_descr)
            data['soil drainage'] =str(row.drai) 
            data['soil class'] =str(row.soil) 
            data['relief'] =str(row.lndf_descr)
            data['slope'] =str(row.slop)

        query_2 = session.query(Aez).filter(func.ST_Contains(Aez.wkb_geometry, func.ST_Transform(func.ST_GeomFromText(f'POINT({point})', 4326), 4326)))
        for i in query_2:
            print(f'Aez zone at this point is: ' , i.aezcode)
            data['Aez'] = str(i.aezcode)

        query_3 = session.query(Rain).filter(func.ST_Contains(func.Geometry(Rain.wkb_geometry),
                                   func.Geometry(func.ST_GeographyFromText(f'POINT({point})'))))
        for i in query_3:
            print(f'Rain at this point is: ' , i.dn, 'mm')
            data['rainfall'] = str(i.dn)


        return Area(data)

    except Exception as e:
        return ErrorModel("Area Not Found")
コード例 #2
0
    def get(self):
        """Get all publications."""
        params = publication_parser.parse_args()
        has_lat = params.latitude is not None
        has_lon = params.longitude is not None
        has_dist = params.max_distance is not None

        if any((has_lat, has_lon, has_dist)) and not all(
            (has_lat, has_lon, has_dist)):
            raise DistanceFilterMissingParameters

        query = Publication.query  # noqa: E712

        for filter_name, filter_op in params.items():
            if not isinstance(filter_op, FilterParam):
                if filter_op is None:
                    continue
                for i in publication_parser.args:
                    if i.name == filter_name:
                        filter_op = i.type(filter_op)
                        break

            if not isinstance(filter_op, FilterParam):
                continue

            query = filter_op.apply(query, Publication)

        if params.max_distance:
            point = func.ST_GeographyFromText(
                f"POINT({params.latitude} {params.longitude})", srid=4326)

            query = query.filter(
                func.ST_DWithin(Publication.loc, point,
                                params.max_distance * 1000))
        return query.all()
コード例 #3
0
ファイル: crud_post.py プロジェクト: CatDevz/SnapQuest
 def find_by_coordinates(self, db: Session, *, latitude: float,
                         longitude: float,
                         distance: float) -> Optional[List[Post]]:
     POINT = f"POINT({longitude} {latitude})"
     posts = db.query(self.model).filter(
         func.ST_DistanceSphere(
             Post.point, func.Geometry((
                 func.ST_GeographyFromText(POINT)))) < distance).all()
     return posts
コード例 #4
0
 async def filter_pdv_by_lat_and_long(self, lat, lng):
     return self.session.query(PDV) \
         .filter(
             func.ST_Intersects(
                 func.Geometry(PDV.coverage_area),
                 func.Geometry(
                     func.ST_GeographyFromText(f'POINT({lat} {lng})')
                 )
             )
         ) \
         .all()
コード例 #5
0
ファイル: crud_post.py プロジェクト: CatDevz/SnapQuest
    def get_many(self,
                 db: Session,
                 *,
                 skip: int = 0,
                 limit: int = 100,
                 descending: bool = False,
                 lat: float,
                 lan: float,
                 distance: float) -> Optional[List[Post]]:

        POINT = "POINT({} {})".format(lan, lat)
        posts = db.query(self.model).filter(
            func.ST_DistanceSphere(
                Post.point, func.Geometry((func.ST_GeographyFromText(POINT))))
            < distance).offset(skip).limit(limit).all()

        return posts
コード例 #6
0
ファイル: airport.py プロジェクト: imclab/skylines
 def distance(self, location):
     loc1 = cast(self.location_wkt, Geography)
     loc2 = func.ST_GeographyFromText(location.to_wkt())
     return db.session.scalar(func.ST_Distance(loc1, loc2))
コード例 #7
0
    def on_get(self, req, resp):
        resp.content_type = falcon.MEDIA_JSON

        session = Session()
        matchedSymptoms = json.loads(req.get_header('symptoms'))
        location = 'POINT('+req.get_header("latitude")+' '+req.get_header("longitude")+')'

        clinicsForSympts = []
        for symptId in matchedSymptoms:
            clinicsForSympts.append(
                set(
                    session.query(Clinic.id)
                    .join(Clinic.doctors)
                    .join(Doctor.specialities)
                    .join(Speciality.symptoms)
                    .filter(Symptom.id == symptId)
                    .distinct(Clinic.id)
                    .all()
                )
            )

        matchedClinics = set(clinicsForSympts[0]).intersection(*clinicsForSympts)

        closestClinic = session.query(Clinic.id) \
            .filter(Clinic.id.in_(matchedClinics)) \
            .order_by(asc(func.ST_Distance(Clinic.location, func.ST_GeographyFromText(location)))) \
            .first()

        if closestClinic is None:
            resp.status = falcon.HTTP_404
            resp.body = json.dumps({})
            return

        clinicOutput = session.query(Clinic).filter(Clinic.id == closestClinic.id).first()

        matchedSpecs = session.query(Speciality.id) \
            .join(Speciality.symptoms) \
            .filter(Symptom.id.in_(matchedSymptoms)) \
            .all()

        doctorsOutput = session.query(Doctor).join(Doctor.clinics).join(Doctor.specialities) \
            .filter(Clinic.id == closestClinic.id).filter(Speciality.id.in_(matchedSpecs)).distinct(Doctor.id).all()

        specsOutput = session.query(Speciality.name).join(Clinic.doctors).join(Doctor.specialities)\
            .filter(Clinic.id == closestClinic.id).filter(Speciality.id.in_(matchedSpecs))

        losationStringX = session.query(func.ST_X(clinicOutput.location).label('x')).first()
        losationStringY = session.query(func.ST_Y(clinicOutput.location).label('y')).first()

        respp = {
            'name': clinicOutput.name,
            'location': str(losationStringX.x) + ' ' + str(losationStringY.y),
            'opening': str(clinicOutput.opening),
            'closure': str(clinicOutput.closure),
            'doctors':  [{
                'fname': doctor.first_name,
                'sname': doctor.second_name,
                'pname': doctor.fathers_name,
                'specialities': [
                    spec.name for spec in specsOutput.filter(Doctor.id == doctor.id).all()
                ],
                'cabinet': doctor.cabinet,
                'phone': doctor.phone
                } for doctor in doctorsOutput
            ]
        }
        resp.body = json.dumps(respp)
        resp.status = falcon.HTTP_200