Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

How can I make a shape file of an csv file with coordinates?

share|improve this question
3  
What software are you using? –  GIS-Jonathan May 4 '12 at 12:12
    
Possible duplicate question. gis.stackexchange.com/questions/327/… –  artwork21 May 4 '12 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. –  Dano May 4 '12 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. –  Mark Ireland May 4 '12 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 .... –  Dano May 4 '12 at 20:28
show 1 more comment

9 Answers 9

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

share|improve this answer
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. –  lynxlynxlynx Aug 22 '12 at 10:14
add comment

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

share|improve this answer
add comment

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...

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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
share|improve this answer
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.