0

I have a large polygon file in the form of .gdb (mygdb, ~10gb) and I need to crop it using another polygon shapefile (myshp, ~10mb). I want to do this PostGIS database using R so that it will be faster and R won't crash. I already have them exported to my postGIS database. (say, schema = myschema, table = mytab1 for mygdb and table = mytab2 for myshp) I know if I have them locally saved I can do using sf::st_intersection(x,y). But I am finding it hard to find any proper help on how to do this without importing them in R. I understand I need to write some SQL code inside the st_intersection to do this in PostGIS database without importing them again in R. I am a beginner in SQL and not sure what exactly to write inside the function. Could somebody please help me with this?

3
  • You should be able to use one of R's PostgreSQL access packages and do the query directly on the database, and not using R's st_intersection function at all.
    – Spacedman
    Commented Feb 4, 2022 at 16:49
  • Thank you. Would you mind illustrating this with an example or pointing me to a guide to get me started?
    – rm167
    Commented Feb 4, 2022 at 17:24
  • 1
    Install cran.r-project.org/web/packages/RPostgreSQL/index.html and work through basic SQL examples of how to run SQL. Then read PostGIS docs for spatial operations. No time for full answer right now, hope this is better than nothing.
    – Spacedman
    Commented Feb 4, 2022 at 18:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.