def geom(self): def cut_mount_lawley(): return self.cut_locality( "Mount Lawley", (MountLawley.MTLAWLEY_JOHN_THIRD, 2) ) def cut_inglewood(): return self.cut_locality("Inglewood", (MountLawley.INGLEWOOD_JOHN_ST, 2)) return func.ST_Union( self.get_locality_by_name("Maylands"), func.ST_Union(cut_mount_lawley(), cut_inglewood()), )
def geom(self): def cut_bayswater(): return self.cut_locality("BAYSWATER", (Bayswater.BAYSWATER_GREY_ST, 2)) return func.ST_Union( self.locality_union("Bassendean", "Ashfield"), cut_bayswater() )
def post_process(cls, db, **kwargs): if hasattr(cls, 'geom'): from gtfsdb.model.route import Route db.prep_an_orm_class(Route) log.debug('{0}.post_process'.format(cls.__name__)) ada = cls(name='ADA Boundary') # 3960 is the number of feet in 3/4 of a mile this is the size of the buffer around routes that # is be generated for the ada boundary # todo: make this value configurable ... and maybe metric ... # todo: the following doesn't work ... too big of a buffer ... so # the buffer values of 0.0036 is not scientifically determined ... rather it looks good on a limited case geom = db.session.query( func.ST_ExteriorRing( func.ST_Union( Route.geom.ST_Buffer(0.011025, 'quad_segs=50') ) ) ) geom = func.ST_MakePolygon(geom) # TODO: clip the ADA geom against the District geom ... no ADA outside legal transit district ada.geom = geom db.session.add(ada) db.session.commit() db.session.close()
def geom(self): def cut_morley(): return self.cut_locality("MORLEY", (self.MORLEY_WALTER_RD, 2)) def cut_bedford(): return self.cut_locality("BEDFORD", (self.BEDFORD_BEAUFORT_ST, 2)) def cut_bayswater(): return self.cut_locality("BAYSWATER", (self.BAYSWATER_GREY_ST, 1)) morley = cut_morley() bayswater = cut_bayswater() embleton = self.get_locality_by_name("EMBLETON") bedford = cut_bedford() return func.ST_Union( func.ST_Union(func.ST_Union(bedford, bayswater), embleton), morley )
def geom(self): def cut_bedford(): return self.cut_locality("BEDFORD", (Bayswater.BEDFORD_BEAUFORT_ST, 1)) def cut_inglewood(): return self.cut_locality( "Inglewood", (self.INGLEWOOD_JOHN_ST, 1), (self.INGLEWOOD_DUNDAS, 1) ) def cut_mount_lawley(): return self.cut_locality( "Mount Lawley", (self.MTLAWLEY_JOHN_THIRD, 1), (self.MTLAWLEY_LONGROYD_NORTH_WALCOTT, 1), ) return func.ST_Buffer( func.ST_Union( func.ST_Union(cut_bedford(), cut_inglewood()), cut_mount_lawley() ), 0.1, )
def geom(self): def cut_hamilton_hill(): return self.cut_locality("Hamilton Hill", (self.HAMILTON_CARRINGTON, 2)) return func.ST_Union( self.locality_union( "Fremantle", "North Fremantle", "East Fremantle", "Palmyra", "Beaconsfield", ), cut_hamilton_hill(), )
def resolve(self, db, network_elements): """ network_elements should be in consecutive order. jumps between non-contiguous elements will result in an interpolated join in the resulting line """ session = db.session() try: q = session.query( func.ST_AsGeoJSON( func.ST_Multi(func.ST_Union(db.RoadNetwork.geom)))).filter( db.RoadNetwork.network_element.in_(network_elements)) cut = q.one()[0] finally: session.close() return json.loads(cut)
def calculated_boundary(cls, db): """ # Fill holes in buffered district map # https://geospatial.commons.gc.cuny.edu/2013/11/04/filling-in-holes-with-postgis/ # https://postgis.net/docs/ST_ExteriorRing.html # NOTE ST_ExteriorRing won't work with MULTIPOLYGONS # https://postgis.net/docs/ST_Buffer.html """ from gtfsdb.model.route import Route db.prep_an_orm_class(Route) log.info('calculating the service district boundary from an abitrary buffer / extent on routes') geom = db.session.query( func.ST_ExteriorRing( func.ST_Union( Route.geom.ST_Buffer(0.0313, 'quad_segs=4 endcap=square join=mitre mitre_limit=1.0')))) ret_val = func.ST_MakePolygon(geom) return ret_val
def get_cut(self, db): f = func.ST_Multi( func.ST_GeomFromGeoJSON(json.dumps(self._paths[0].get_path(db)))) for p in self._paths[1:]: f = func.ST_Union( f, func.ST_GeomFromGeoJSON(json.dumps(p.get_path(db)))) session = db.session() try: q = session.query(f) # log for debugging purposes session.add( db.Cut(description=self._description, geom=func.ST_Transform(q, 4326))) session.commit() return q.one()[0] finally: session.close()
def locality_union(self, *args): res = func.ST_Union(self.get_locality_by_name(args[0]), self.get_locality_by_name(args[1])) for locality in args[1:]: res = func.ST_Union(res, self.get_locality_by_name(locality)) return res