def test_extent(self): l = session.query(functions.extent(Lake.lake_geom)). \ filter(Lake.lake_geom != None).scalar() r = session.query(functions.extent(Road.road_geom)). \ filter(Road.road_geom != None).scalar() s = session.query(functions.extent(Spot.spot_location)). \ filter(Spot.spot_location != None).scalar() sh = session.query(functions.extent(Shape.shape_geom)). \ filter(Shape.shape_geom != None).scalar() eq_( l, "BOX(-89.1329617834395 42.565127388535,-88.0846337579618 43.243949044586)" ) eq_( r, "BOX(-89.2449842484076 42.5082802993631,-88.0110670509554 43.3175159681529)" ) eq_( s, "BOX(-89.201512910828 42.6269904904459,-88.3304141847134 43.1051752038217)" ) eq_( sh, "BOX(-88.7968950764331 42.5584395350319,-88.0110670509554 43.2339172420382)" )
def test_extent(self): l = session.query(functions.extent(Lake.lake_geom)). \ filter(Lake.lake_geom != None).scalar() r = session.query(functions.extent(Road.road_geom)). \ filter(Road.road_geom != None).scalar() s = session.query(functions.extent(Spot.spot_location)). \ filter(Spot.spot_location != None).scalar() sh = session.query(functions.extent(Shape.shape_geom)). \ filter(Shape.shape_geom != None).scalar() eq_(l, "BOX(-89.1329617834395 42.565127388535,-88.0846337579618 43.243949044586)") eq_(r, "BOX(-89.2449842484076 42.5082802993631,-88.0110670509554 43.3175159681529)") eq_(s, "BOX(-89.201512910828 42.6269904904459,-88.3304141847134 43.1051752038217)") eq_(sh, "BOX(-88.7968950764331 42.5584395350319,-88.0110670509554 43.2339172420382)")
), Shape( shape_name='Jogging Track', shape_geom= 'GEOMETRYCOLLECTION(LINESTRING(-88.2652071783439 42.5584395350319,-88.1598727834395 42.6269904904459,-88.1013536751592 42.621974566879,-88.0244428471338 42.6437102356688,-88.0110670509554 42.6771497261147))' ), Shape( shape_name='Play Ground', shape_geom= 'GEOMETRYCOLLECTION(POLYGON((-88.7968950764331 43.2305732929936,-88.7935511273885 43.1553344394904,-88.716640299363 43.1570064140127,-88.7250001719745 43.2339172420382,-88.7968950764331 43.2305732929936)))' ), Overlap(geom='POLYGON((0 0,0 50,50 50,50 0,0 0))'), Overlap(geom='POLYGON((20 20,20 80,80 80,80 20,20 20))'), ]) # or use an explicit WKTSpatialElement (similar to saying func.GeomFromText()) r = Road( road_name='Dave Cres', road_geom=WKTSpatialElement( 'LINESTRING(-88.6748409363057 43.1035032292994,-88.6464173694267 42.9981688343949,-88.607961955414 42.9680732929936,-88.5160033566879 42.9363057770701,-88.4390925286624 43.0031847579618)', 4326)) session.add(r) session.commit() print session.query(functions.extent( Overlap.geom)).filter(Overlap.geom != None).one() print session.query(pg_functions.wkt(functions.union( Overlap.geom))).filter(Overlap.geom != None).one() print session.query(pg_functions.wkt(functions.collect( Overlap.geom))).filter(Overlap.geom != None).one()
Road(road_name='Jeff Rd', road_geom='LINESTRING(-88.9139332929936 42.5082802993631,-88.8203027197452 42.5985669235669,-88.7383759681529 42.7239650127389,-88.6113059044586 42.9680732929936,-88.3655256496815 43.1402866687898)'), Road(road_name='Peter Rd', road_geom='LINESTRING(-88.9139332929936 42.5082802993631,-88.8203027197452 42.5985669235669,-88.7383759681529 42.7239650127389,-88.6113059044586 42.9680732929936,-88.3655256496815 43.1402866687898)'), Road(road_name='Geordie Rd', road_geom='LINESTRING(-89.2232485796178 42.6420382611465,-89.2449842484076 42.9179140573248,-89.2316084522293 43.106847178344,-89.0710987261147 43.243949044586,-89.092834566879 43.2957802993631,-89.092834566879 43.2957802993631,-89.0309715095541 43.3175159681529)'), Road(road_name='Paul St', road_geom='LINESTRING(-88.2652071783439 42.5584395350319,-88.1598727834395 42.6269904904459,-88.1013536751592 42.621974566879,-88.0244428471338 42.6437102356688,-88.0110670509554 42.6771497261147)'), Road(road_name='Graeme Ave', road_geom='LINESTRING(-88.5477708726115 42.6988853949045,-88.6096339299363 42.9697452675159,-88.6029460318471 43.0884554585987,-88.5912422101911 43.187101955414)'), Road(road_name='Phil Tce', road_geom='LINESTRING(-88.9356689617834 42.9363057770701,-88.9824842484076 43.0366242484076,-88.9222931656051 43.1085191528662,-88.8487262866242 43.0449841210191)'), Lake(lake_name='My Lake', lake_geom='POLYGON((-88.7968950764331 43.2305732929936,-88.7935511273885 43.1553344394904,-88.716640299363 43.1570064140127,-88.7250001719745 43.2339172420382,-88.7968950764331 43.2305732929936))'), Lake(lake_name='Lake White', lake_geom='POLYGON((-88.1147292993631 42.7540605095542,-88.1548566878981 42.7824840764331,-88.1799363057325 42.7707802547771,-88.188296178344 42.7323248407643,-88.1832802547771 42.6955414012739,-88.1565286624204 42.6771496815287,-88.1448248407643 42.6336783439491,-88.131449044586 42.5718152866242,-88.1013535031847 42.565127388535,-88.1080414012739 42.5868630573248,-88.1164012738854 42.6119426751592,-88.1080414012739 42.6520700636943,-88.0980095541401 42.6838375796178,-88.0846337579618 42.7139331210191,-88.1013535031847 42.7423566878981,-88.1147292993631 42.7540605095542))'), Lake(lake_name='Lake Blue', lake_geom='POLYGON((-89.0694267515924 43.1335987261147,-89.1078821656051 43.1135350318471,-89.1329617834395 43.0884554140127,-89.1312898089172 43.0466560509554,-89.112898089172 43.0132165605096,-89.0694267515924 42.9898089171975,-89.0343152866242 42.953025477707,-89.0209394904459 42.9179140127389,-89.0042197452229 42.8961783439491,-88.9774681528663 42.8644108280255,-88.9440286624204 42.8292993630573,-88.9072452229299 42.8142515923567,-88.8687898089172 42.815923566879,-88.8687898089172 42.815923566879,-88.8102707006369 42.8343152866242,-88.7734872611465 42.8710987261147,-88.7517515923567 42.9145700636943,-88.7433917197452 42.9730891719745,-88.7517515923567 43.0299363057325,-88.7734872611465 43.0867834394905,-88.7885352038217 43.158678388535,-88.8738057324841 43.1620222929936,-88.947372611465 43.1937898089172,-89.0042197452229 43.2138535031847,-89.0410031847134 43.2389331210191,-89.0710987261147 43.243949044586,-89.0660828025478 43.2238853503185,-89.0543789808917 43.203821656051,-89.0376592356688 43.175398089172,-89.0292993630573 43.1519904458599,-89.0376592356688 43.1369426751592,-89.0393312101911 43.1386146496815,-89.0393312101911 43.1386146496815,-89.0510350318471 43.1335987261147,-89.0694267515924 43.1335987261147))'), Lake(lake_name='Lake Deep', lake_geom='POLYGON((-88.9122611464968 43.038296178344,-88.9222929936306 43.0399681528663,-88.9323248407643 43.0282643312102,-88.9206210191083 43.0182324840764,-88.9105891719745 43.0165605095542,-88.9005573248408 43.0232484076433,-88.9072452229299 43.0282643312102,-88.9122611464968 43.038296178344))'), Spot(spot_height=420.40, spot_location='POINT(-88.5945861592357 42.9480095987261)'), Spot(spot_height=102.34, spot_location='POINT(-88.9055734203822 43.0048567324841)'), Spot(spot_height=388.62, spot_location='POINT(-89.201512910828 43.1051752038217)'), Spot(spot_height=454.66, spot_location='POINT(-88.3304141847134 42.6269904904459)'), Shape(shape_name='My Shapes', shape_geom='GEOMETRYCOLLECTION(POINT(-88.3304141847134 42.6269904904459),LINESTRING(-88.2652071783439 42.5584395350319,-88.1598727834395 42.6269904904459,-88.1013536751592 42.621974566879,-88.0244428471338 42.6437102356688,-88.0110670509554 42.6771497261147),POLYGON((-88.7968950764331 43.2305732929936,-88.7935511273885 43.1553344394904,-88.716640299363 43.1570064140127,-88.7250001719745 43.2339172420382,-88.7968950764331 43.2305732929936)))'), Shape(shape_name='Jogging Track', shape_geom='GEOMETRYCOLLECTION(LINESTRING(-88.2652071783439 42.5584395350319,-88.1598727834395 42.6269904904459,-88.1013536751592 42.621974566879,-88.0244428471338 42.6437102356688,-88.0110670509554 42.6771497261147))'), Shape(shape_name='Play Ground', shape_geom='GEOMETRYCOLLECTION(POLYGON((-88.7968950764331 43.2305732929936,-88.7935511273885 43.1553344394904,-88.716640299363 43.1570064140127,-88.7250001719745 43.2339172420382,-88.7968950764331 43.2305732929936)))'), Overlap(geom='POLYGON((0 0,0 50,50 50,50 0,0 0))'), Overlap(geom='POLYGON((20 20,20 80,80 80,80 20,20 20))'), ]) # or use an explicit WKTSpatialElement (similar to saying func.GeomFromText()) r = Road(road_name='Dave Cres', road_geom=WKTSpatialElement('LINESTRING(-88.6748409363057 43.1035032292994,-88.6464173694267 42.9981688343949,-88.607961955414 42.9680732929936,-88.5160033566879 42.9363057770701,-88.4390925286624 43.0031847579618)', 4326)) session.add(r) session.commit() print session.query(functions.extent(Overlap.geom)).filter(Overlap.geom != None).one() print session.query(pg_functions.wkt(functions.union(Overlap.geom))).filter(Overlap.geom != None).one() print session.query(pg_functions.wkt(functions.collect(Overlap.geom))).filter(Overlap.geom != None).one()