7

How can I make a shapefile of an CSV file with coordinates?

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked May 4, 2012 at 12:10
6
  • 3
    What software are you using? Commented May 4, 2012 at 12:12
  • Possible duplicate question. gis.stackexchange.com/questions/327/… Commented May 4, 2012 at 13:36
  • Welcome Hans - Try to provide more details in your questions (especially which software you are using). I've posted an answer below assuming you're using ESRI software. Commented May 4, 2012 at 13:38
  • 2
    Actually I like it when there isn't a particular software specified. It gives a chance for different methods to be proposed. And then it is a more comprehensive record and there's less likely to be future duplicates. Commented May 4, 2012 at 17:18
  • @ Mark Ireland - In one sense .... agreed. However, he could accomplish what he's after in ESRI, DNR Garmin, QGIS, CAD ---> That said, the software of choice becomes quite relevant as people may actually put a substantial amount of time in to answering a question only to find out the person asking the question does not have access to said software. I understand what you're saying too, but .... Commented May 4, 2012 at 20:28

9 Answers 9

8

If you have FME (or the Data Interoperability Extension in ArcGIS) then the solution looks like this:

enter image description here

A CSV reader, 2DPointReplacer transformer, a PointConnector transformer (optional), and a Shape writer. There are some more examples on our FMEpedia knowledgebase.

Pros: Easy and visual. Also flexible (there are simple ways to handle data that is not just x/y but includes headers, etc) and with a much greater range of format support (not just CSV and Shape)

Cons: Not Free/Open-Source software. If this is a one-off project, or you already have one of the other solutions specified here, then it's probably not worth buying FME just for this one task.

2016 Since this question came up on my radar today, I'll add that the latest FME versions have a parameter in the CSV reader to specify which attributes are coordinates. That way you don't need the 2DPointReplacer any more (which is now renamed to the VertexCreator anyway!)

answered May 4, 2012 at 17:33
7
answered May 4, 2012 at 12:35
1
6

The easiest and fastest way of doing it is probably with ogr

In the csv driver doc is an example syntax from csv to shape: http://gdal.org/ogr/drv_csv.html

ogr2ogr -f "ESRI Shapefile" shapefilename.shp PG:"host=host user=user 
dbname=databasename password=password" -sql "SELECT the_geom FROM tablename"

HTH Nicklas

urcm
22.6k4 gold badges59 silver badges109 bronze badges
answered May 4, 2012 at 12:16
2
  • 1
    Doesn't this assumes you first imported the CSV into a PostGIS table and made a proper geometry column out of the data there? The driver doc does not mention any examples anymore unfortunately - one would hope you could specify the CSV as a parameter. Commented Aug 22, 2012 at 10:14
  • Updated link to CSV driver: gdal.org/drv_csv.html Commented Feb 8, 2019 at 11:08
5

if you are PostgreSQL/PostGIS user, you can convert your bulk data as following:

1.Create a new table for your csv files.

2.Copy csv to newly created table.

COPY yourNewTableName (lat, long, name, other)
FROM '/path/yourCSVfile.csv' CSV;

3.Now you have to create geometry column for your spatial data.

SELECT addgeometrycolumn('public','yourNewTableName ','the_geom',4326,'POINT');

4.Populating the geometry column from your lat, long with UPDATE function with GeometryFromText function of PostGIS.

UPDATE yourNewTableName SET the_geom = GeometryFromText('POINT('||lat||' '||long||')',4326);

5.The last thing, you can connect to QGIS for exporting format of shp or the following code:

pgsql2shp -s 4326 -W latin5 -f newSHP -h localhost -u username -P password
yourdataBaseName "SELECT * FROM yourNewTableName"

and you can use How to convert PostGIS table to Shapefile in Python? or csv2shp (CSV to Shapefile Converter) tool for bulk converting...

i hope it helps you...

answered May 4, 2012 at 13:28
2

First, be certain there are "no" special characters or spaces in the column headings (the only exception is "underscore"). For example, if you have a name like "Borehole ID", change it to something like "BH_ID" or "BHID". Assuming you're using ArcMap, navigate to the .csv file (either in Catalog, or in the Catalog window in ArcMap), right mouse over your .csv file, select "Create Feature Class" ----> and then "From XY Table". The image shown below is what you'll see next. Populate the "X Field" with your Easting column header and your "Y Field" with the Northing Column header. You can leave the "Z Field" blank unless you want to assign elevations to your points. Next, click on the area that says "Coordinate System of Input Coordinates". Here, you will assign the appropriate projection/datum/zone. Lastly (near the bottom) hit the folder and route to the appropriate directory on your computer or server, and name your new shapefile.

enter image description here

answered May 4, 2012 at 13:27
2

Although not Shape, another way to convert text-based X/Y coordinates to a spatial dataset is to load them into Google Fusion Tables. From there you can export them to a KML dataset.

I suggest this because whatever application you're going to use Shape in, it may also support KML natively. Many do.

answered May 4, 2012 at 17:40
2

Here's an arcpy-based solution.

"Takes a CSV as input, write a SHP as output"
import arcpy
import os
csv_input = r"C:\path\to\input.csv"
shp_output_dir = os.path.dirname(csv_input)
temp_layer = os.path.splitext(os.path.basename(csv_input))[0] # == "input"
# OP NOTE - you say "coordinates" and I assumed you meant WGS84 latitude/longitude. If not, this is NOT your projection
WGS84_PROJ = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];IsHighPrecision"
# OP NOTE - if the latitude/longitude fields aren't named as such you'll need to update this
arcpy.MakeXYEventLayer_management(csv_input, "LATITUDE", "LONGITUDE", temp_layer, WGS84_PROJ)
# OP note: this exports a feature to a directory as a shapefile.
# You don't specify the name directly, it's just taken from the existing `temp_layer` name
arcpy.FeatureClassToShapefile_conversion(temp_layer, shp_output_dir)
arcpy.Delete_management(temp_layer) # clean up layer, for completeness
answered Jul 13, 2012 at 23:49
1

I'm sure there are lots of examples of how to do this. You can see how to do this in SpatiaLite (with both GUI and command line options) at http://www.gaia-gis.it/gaia-sins/spatialite-cookbook/html/impexp.html

answered Jul 14, 2012 at 3:55
1

Add your csv file in Table of Contents in ArcGIS Desktop. Right click on your data and go for Display XY Data. Selecet your X and Y field, also coordinate system. Then you have a visualization of your points. You can also right click and export your visualization as shapefiles.

The reason I prefer this method instead of converting to shapefiles right away is this way you can preview your file before actually convert and save it to your disk, with potential errors.

answered Jul 14, 2012 at 8:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.