# How to add coordinate system to shapefile source layer via Web API

I have a Web API that creates a shapefile on demand for the user to download over the browser. The geometries are all points and in WGS84 projection. I'm running into an issue where the ogr2ogr is throwing this error when I apply a transform to it:

Can't transform coordinates, source layer has no coordinate system. Use -s_srs to set one.

My question is how do I correctly create the shapefile so ogr2ogr can at correctly guess which coordinate system I'm using. Because I'm not saving the files to disk, I'm actually building the byte array of the .shp file following the shapefile technical description ESRI Shapefile Technical Description

If I use -s_srs or -a_srs to manually assign it with SRID 4326, then ogr2ogr will work.

EDIT: in response to iant's comment, I do have the .prj file in the same directory as the .shp file and they share the same filename.

I found the cause of my issue. I needed to set the bounding box in the shapefile header when I create the file and the .prj files needs to be UTF-8 format.

Shapefiles carry their projection information (when present) in a .prj sidecar file. The contents of these files can be found on http://epsg.io so for epsg:4326 you need a file containing:

GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]

• Sorry I should have specified that in the original question. I do have the .prj file in the same directory as the .shp file and it does contain the same text you provided. I still get the same result. – zeto31 Jun 23 '17 at 12:01