joining two shapefiles

25 views
Skip to first unread message

tarkenton

unread,
Aug 12, 2009, 6:50:44 PM8/12/09
to JEQL Users
Hey Martin

Still trying to get my head wrapped around JEQL syntax. Have a simple
script pasted below. Am trying to read in two shape files, calculate
the intersection and then dump out the results. Can't figure out
what is wrong with the syntax!

ShapefileReader jumbo
file: "jumbo.shp";

ShapefileReader fordist
file: "fordist.shp";

spatial_join = "select jumbo.*, fordist.* from jumbo join parks on
Geom.intersects(jumbo.GEOM, fordist.GEOM)";

ShapefileWriter spatial_join file: "jum_prk.shp";

I am making the assumption here that the Geom.intersects() function
will combine the linework from the two inputs as oppose to selecting
features from one table that intersect with those of anther. is this
correct?

Kevin

Martin Davis

unread,
Aug 12, 2009, 9:30:31 PM8/12/09
to jeql-...@googlegroups.com
Hi, Kevin.

The following is correct syntax, with some logic corrections too.  Note no quotes around the SELECT expression, and I changed the "parks" name to be fordist.

spatial_join = select jumbo.*, fordist.* from jumbo join fordist on
Geom.intersects(jumbo.GEOMETRY, fordist.GEOMETRY);

But if you want to combine linework, this isn't the right code to use.  intersects() tests to see whether one geometry intersects another.  So the above selects all combinations of jumbo and fordist where the features intersect each other - but it doesn't compute any new geometry.

If you want the actual intersection, you could try something like this:

spatial_join = select jumbo.* except GEOMETRY, fordist.* except GEOMETRY,
Geom.intersection( jumbo.GEOMETRY, fordist.GEOMETRY) geom
from jumbo join fordist on
Geom.intersects(jumbo.GEOMETRY, fordist.GEOMETRY);

Note the use of the EXCEPT clause to omit the geometry fields from the input tables when copying to the output - this leaves you with just one geometry column, the intersection.  (EXCEPT is pretty new functionality - if you hit a problem using it, just specify the fields you want to copy explicitly)

Hope this helps...

Martin
Reply all
Reply to author
Forward
0 new messages