Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a simple (and maybe stupid) question for you today.

I have to compute intersection points between GIS polygons and imaginary lines I draw thanks to a script of mine... And I wonder if it would be relevant to use PostGIS instead of a Math module to catch intersection points.

Thank you.

EDIT: by math module (or library) I think about a mathematic module as I work on a Python script. So that is a "python math module".

share|improve this question
1  
PostGIS has a function called ST_INTERSECTIONS(geom1, geom2) which returns the interestions of two geometries. I use it with a WHERE ST_INTERSECTS(geom1, geom2). This sounds like it'll do what you're asking. I don't know what "imaginary" means in the context of geometries, though. –  canisrufus Sep 1 '11 at 13:06
    
@canisrufus: "imaginary" means "not a data extracted from a real geographical information from our planet earth"... it means "a line I draw on a real map". Thank for the ST_INTERSECTIONS I know it but I wonder how fast it can be against a Math library... –  Rootosaurus Sep 1 '11 at 13:40
    
What exactly do you mean by a "Math module" or "Math library"? –  whuber Sep 1 '11 at 14:12
    
@whuber oh! sorry, let me edit my question for that "module/library" thing. –  Rootosaurus Sep 1 '11 at 18:59
1  
Thanks, but the update's not very specific. What functions does this library support? In particular, does it provide computational geometry functionality to manage and search polylines and polygons, or is it at a lower level than that? –  whuber Sep 1 '11 at 19:03

3 Answers 3

up vote 5 down vote accepted

Keep in mind that ST_INTERSECTIONS will make use of a spatial index whereas your math library may not. Not only must you determine if a line intersects a polygon, but which polygons to test for each line. A good spatial index with possibly fish-netting of these polygons can vastly speed up a spatial query like this. Not to mention if you have a large amount of polygons, you'll save time by not having to load all of the polygons into memory.

Unless you are loading a lot of data from this query from PostGIS over a slow network on another machine, the overhead is probably negligible.

share|improve this answer

If by "using a math module," you mean manually writing out formulas to compute an intersection, then you should really use PostGIS. No sense in reinventing the wheel!

Do note, however, that your data will need to be loaded into a PostGIS database.

So if your original data came in the form of shapefiles, you'll need to load that into a PostGIS database with shp2pgsql, for example. And if your script is generating a start- and endpoint for a line as human-readable (x,y) coordinates, you would need to convert those coordinates into a geometry using ST_GeomFromText.

share|improve this answer

I think that the Shapely Python package would work great for what you need. It uses the exact same geometry library that PostGIS uses, without the need for an underlying RDBMS.

http://pypi.python.org/pypi/Shapely

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.