-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notes on shapefile loading #3
Comments
I've run through these steps, adding the exported data to the database and also some new data. I've scripted some of these steps here: /proj/ie/proj/EMAQ/Platform/Surrogates/2014/Spatial-Allocator/pg_srgcreate. I'll get a hold of the java tools and give that a try for creating the surrogates. |
I've added newly exported shapefiles to /proj/ie/proj/SA/pg_srgcreate/shp_export/:
For the pop/housing shapefile, I wasn't sure which fields are needed, so I exported everything. I'm not sure if the multiple geometry columns will cause problems or if the extras just get imported as strings. |
For the fix geometry steps, how do you know if PostGIS considers the geometries to be invalid? and does this need to be done for all shapefiles? Another question is when you say, "a new geometry column corresponding to the grid's projection needs to be created", you mean the modeling grid projection, not the shapefile projection, right? |
To check for invalid geometries, you can run a query like: SELECT COUNT(*) FROM schema.table
WHERE NOT ST_IsValid(wkb_geometry); If the count comes back greater than zero, there are invalid geometries. Regarding the new geometry column, that refers to transforming the geometry from the shapefile's original projection into the output modeling grid projection. |
A table can have multiple geometry columns, each of which is in a different projection. If the geometries in the first projection are all made valid, and then those are projected and saved to a new column, those geometries are also valid. |
Is there anyway to generalize the weight processing script to run on any shapefile: /proj/ie/proj/EMAQ/Platform/Surrogates/2014/Spatial-Allocator/pg_srgcreate/PGgrid_12km_scripts/acs_2014_prcs_script.sh. This script has all kinds of hard coded attributes. Can we just pass attributes along from the input "uncut" file to allow this script to be extensible? |
I created shapefiles from the existing surrogate processing that contain just the columns needed and have the geometries already converted to the EPA's grid projection. These are in /proj/ie/proj/SA/pg_srgcreate/shp_export/.
The first step to loading these shapefiles is to define the grid projection in the
spatial_ref_sys
table in the database.Or from the command line:
psql -h myserver -d mydb -U myuser -f create_900921.sql
To load a shapefile into a Postgres table, use the
shp2pgsql
command:shp2pgsql -s 900921 -g geom_900921 -D -I ./pil2016_16aug.shp public.pil2016_16aug | psql -h myserver -d mydb -U myuser
The flag
-s 900921
indicates that the geometries inside thepil2016_16aug
shapefile use the projection corresponding to SRID 900921 in thespatial_ref_sys
table.-g geom_900921
specifies the name of the geometry column in the created database table.-D
uses the Postgres data dump format.-I
creates an index on the geometry column after the data is imported../pil2016_16aug.shp
is the shapefile to read.public.pil2016_16aug
is the schema and table name to create.psql -h myserver -d mydb -U myuser
is the connection information for the Postgres server.Generic shapefile import
When working with other shapefiles, the
ogr2ogr
tool may be more useful thanshp2pgsql
. It has more options thanshp2pgsql
, including automatically determining the projection based on the shapefile's .prj file.ogr2ogr -f "PostgreSQL" "PG:dbname=mydb" shapefile.shp -nln schema.table -nlt PROMOTE_TO_MULTI
Shapefiles can have geometries that PostGIS considers invalid. To fix these geometries, use the ST_MakeValid function.
After the shapefile has been loaded, a new geometry column corresponding to the grid's projection needs to be created. For example, assuming the grid SRID is 900921:
where geomtype = MultiPolygon, Point, etc. matching the original geometry column.
The text was updated successfully, but these errors were encountered: