Skip to content

Commit d3b6e2a

Browse files
Update README.md
Added .prj information based on some complaints in blog posts and youtube videos about PyShp.
1 parent c35592c commit d3b6e2a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,20 @@ If you do not use the autoBalance() or balance() method and forget to manually
10771077
balance the geometry and attributes the shapefile will be viewed as corrupt by
10781078
most shapefile software.
10791079

1080+
### Writing .prj files
1081+
A .prj file, or projection file, is a simple text file that stores a shapefile's map projection and coordinate reference system to help mapping software properly locate the geometry on a map. If you don't have one, you may get confusing errors when you try and use the shapefile you created. The GIS software may complain that it doesn't know the shapefile's projection and refuse to accept it, it may assume the shapefile is the same projection as the rest of your GIS project and put it in the wrong place, or it might assume the coordinates are an offset in meters from latitude and longitude 0,0 which will put your data in the middle of the ocean near Africa. The text in the .prj file is a [Well-Known-Text (WKT) projection string](https://en.wikipedia.org/wiki/Well-known_text_representation_of_coordinate_reference_systems). Projection strings can be quite long so they are often referenced using numeric codes call EPSG codes. The .prj file must have the same base name as your shapefile. So for example if you have a shapefile named "myPoints.shp", the .prj file must be named "myPoints.prj".
10801082

1083+
If you're using the same projection over and over, the following is a simple way to create the .prj file assuming your base filename is stored in a variable called "filename":
1084+
1085+
>>> with open("{}.prj".format(filename), "w") as prj:
1086+
>>> wkt = 'GEOGCS["WGS 84",'
1087+
>>> wkt += 'DATUM["WGS_1984",'
1088+
>>> wkt += 'SPHEROID["WGS 84",6378137,298.257223563]]'
1089+
>>> wkt += ',PRIMEM["Greenwich",0],'
1090+
>>> wkt += 'UNIT["degree",0.0174532925199433]]'
1091+
>>> prj.write(wkt)
1092+
1093+
If you need to dynamically fetch WKT projection strings, you can use the pure Python [PyCRS](https://github.com/karimbahgat/PyCRS) module which has a number of useful features.
10811094

10821095
# Advanced Use
10831096

0 commit comments

Comments
 (0)