2

I have a PostGIS dataset with just over 2 million rows. Each row has a PostGIS geometry point value and several attributes.

I'd like to do some analysis on certain subsets of the data, but I can't figure this out. Is there a way of querying data once you have it in GRASS GIS? Alternately, is it possible to leave the attribute data back in Postgres, and then do queries or filters based on this data?

For example, suppose that my 2+ million rows had a boolean column X. How would I run GRASS analysis on the entire dataset, then immediately do the same analysis on only the data where this column is set to false?

2

You can use v.in.ogr to import PostGIS vectors into GRASS, and use the "where=" option to filter out only those rows you want. Additionally, if you set the database connection in GRASS to postgres, then the attribute table will be stored back into the Postgres database, and the vector geometry will be stored in GRASS for further analysis. So (copied from the manual pages):

db.connect driver=pg database="host=my.postgis.server,dbname=mydb"
db.login user=myname [pass=secret]
db.connect -p
v.in.ogr dsn="PG:host=my.postgis.server dbname=mydb user=myname" layer=mypoints \
    output=mypoints_grass type=point \
    where="boolean_column='f'"

Please note: YOu must use a different name for the GRASS vector. If you're storing the attribs in the same Postgres database as the original PostGIS points, then there will be a conflict of table names otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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