Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am interested in generating a polygon grid shape file for the landmass of the world. What I have presently is two tables in postgreSQL. Table 1: Coastal area shapefile ( : Consisits od Linestrings column names : gid, fid, geom Table 2: Polygon grid shape file created for the above Table 1 with the help of QGIS Grid is (1 lat x 1 lon) in size.
column names : gid_grid, id_grid, coord_grid, geom_grid

Now I want to find the polygon grids in Table 2 which are in the land area (even if a small part of coastal line falls inside the grid, it has to be marked as land area).

My initial thought is to find the polygon grids which intercept with any of the coastal lines, and mark it as a land area (using postgis queries). The problem is, it will not find any polygon grids which totally falls inside the land area. Any suggestions please?

share|improve this question
up vote 1 down vote accepted

You're looking for linestrings that intersect polygons; ST_Intersects is the filter function you want to use e.g.

SELECT linestrings.geom
  FROM linestrings, polygons
 WHERE ST_Intersects(linestrings.geom, polygons.geom) AND polygons.gid_grid = [gid_grid]

Fill in the gid_grid of the polygon you're interested in at the moment. You can get a whole table of the intersections at once with a spatial join:

SELECT linestrings.gid AS linestringID, polygons.gid AS xpolygonsID
  FROM linestrings
 INNER JOIN polygons
    ON ST_Intersects(linestrings.geom, polygons.geom)

As described in the PostGIS reference:

Overlaps, Touches, Within all imply spatial intersection. If any of the aforementioned returns true, then the geometries also spatially intersect. Disjoint implies false for spatial intersection.

share|improve this answer

Your Answer


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.