0

I have a point shapefile called pointA that has a field called fieldB, and a polygon file called polygonC, and I want to calculate the sum of fieldB for all the points that are within polygonC

How to do this?

1 Answer 1

4

Load your shapefile(s) in as per instructions from http://suite.opengeo.org/docs/latest/dataadmin/pgGettingStarted/shp2pgsql.html

Then query using something like

SELECT sum(pointA.fieldB) FROM pointA, polygonC WHERE ST_Within(pointA.the_geom, polygonC.the_geom) AND polygonC.id = ? 
6
  • 1
    I think he intends to get all the points within the polygons, the last line ( second condition in where ) is optional, if I understood well what he wants Commented Jul 15, 2016 at 16:03
  • Hey @HichamZouarhi! Well I'm getting an error saying PolygonC does not exist when the table is clearly there. ERROR: relation "polygonC" does not exist Commented Jul 15, 2016 at 16:17
  • 1
    Hi there @Luffydude, one of the problems with postgresql is the name of tables with caps, that's why you'll have to change it to "polygonC" Commented Jul 15, 2016 at 16:24
  • The query worked now but nothing happened, the result box is completely empty Commented Jul 15, 2016 at 16:26
  • 1
    I tried it in my configuration and it worked, have you tried it without the last condition ( AND polygonC.id = ? ) ? Commented Jul 15, 2016 at 16:40

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.