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 convert a shape file (GIS) to text?
or, How can I extract the information in a shape file?

share|improve this question

migrated from superuser.com Mar 16 '11 at 16:01

This question came from our site for computer enthusiasts and power users.

1  
This question is on-topic for Super User, but you might get a more detailed, accurate response on gis.stackexchange.com. You don't need to ask your question a second time; if you would like it migrated, flag for a moderator and they can move it for you. Either way, it might be helpful to update your question with more details about what GIS software you are using if you want more specific help. Good luck solving your problem! –  nhinkle Feb 25 '11 at 7:06
7  
This is an exact duplicate of gis.stackexchange.com/questions/7339/shapefiles-to-text : the answers are already there. They also appear at gis.stackexchange.com/questions/5962/… and gis.stackexchange.com/questions/6806/… . –  whuber Apr 1 '11 at 19:15
    
@whuber, sorry for asking a duplicate question, however none of the other answers mention pyshp (as far as I can tell), which is what I ended up using, so in a way I am glad I asked. –  instanceofTom Apr 1 '11 at 19:51
    
2 votes left to close duplicate –  Mapperz Apr 1 '11 at 20:42
    
@instance I'm glad it worked out for you. A better way to get answers--and a way to get even better answers--is to acknowledge the previous threads and indicate why the existing answers might not suffice in your case. For instance, you might have specified you were looking for a Python solution. –  whuber Apr 2 '11 at 17:49

12 Answers 12

if you want to draw it on map you can convert shape file into WKT(well known text) format then you can store it in to DB or use it what ever you want to, with your shape file

share|improve this answer

There seems to be a few questions for this across the site. I just posted an answer at another location. See How to get all the lat/long coords that define a shapefile

share|improve this answer

load them to PostGIS.

query them something like:

Select st_x(the_geom) as Xcoord, st_y(the_geom) as Ycoord, attr1, attr2 from table1;

you can output the query directly to csv from pgadmin.

if you geometries is linestrings or polygons and you want all the vertexpoints, just do the same but split to points with st_dumppoints.

/Nicklas

share|improve this answer

If you want to write a little bit of Python, you can use pyshp to read in all the shapefiles and output the X/Y for points or vertices for lines/polygons. Should require a minimal amount of code to get working.

Some sample code from their site:

import shapefile
sf = shapefile.Reader("shapefiles/blockgroups")
shapes = sf.shapes()

Shapes will contain an array of shapes

points = shapes[0].points

Points will contain all the points of the shape at index 0.

share|improve this answer
    
Ill give this a try, thanks. Is there anything in pyshp that would allow me to reproject the shapefiles so that the X/Ys are Latitude/Longitudes? –  instanceofTom Apr 1 '11 at 19:29
    
Nevermind my previous comment, the data is already stored in Lat/Lng –  instanceofTom Apr 1 '11 at 19:44
1  
Nice! I hadn't heard of pyshp before - could have used it a few months back. –  Timothy Michael Apr 1 '11 at 20:13

You can use GDAL/OGR with the ogr2ogr command and export to a csv file, for example:

$ ogr2ogr -f CSV output.csv myshape.shp -lco GEOMETRY=AS_WKT

note that you may serialize the geometry in a variety of formats (WKT, XY, XYZ). Please refer to the official documentation, it is very well explained.

share|improve this answer

The utility ogrinfo should be able to do that. I have never tried it with a shapefile but it works fine for me with other GIS formats. Try something like that:

ogrinfo -al myshapefile.shp

On Windows you can easily get a compiled version of ogrinfo by installing FWtools.

share|improve this answer

With QGIS you can open Shapefiles and either export them as CSV or just copy-paste selected features from the map window into a text editor. You'll get WKT of the geometries and all attribute values.

share|improve this answer

Using OrbisGIS, you'll be able to open your shapefile and export its content in a CSV file. You'll retrieve a set of lines, each containing a record present in the shapefile. your geometries will be stored as well kown text (WKT) values

share|improve this answer

Just look at the folder with your shapefile in Windows Explorer rather than ArcCatalog and you will see the shapefile is actually several files. Your attribute information, which I am guessing is what you want in a text file is in the .dbf, just open that in Excel, Access, Open Office, etc and save as you wish.

share|improve this answer

If you have ArcGIS you can use an out of the box script available from ArcToolbox located here:

Samples\Data Management\Features\Write Features To Text File

If you need further formatting of the text file then a Python script would be the way to go...

share|improve this answer
    
Just and FYI, but while this does write out the feature vertices to points to a text file, it does not write the data out as OGC compliant Well Known Text (WKT), in case that is what you are looking for. –  RyanDalton Apr 22 '13 at 19:20

A shape file map consists of the geometry (.shp), the spatial index (.shx), the attribute table (.dbf) and the projection metadata file (.prj). The geometry you could represent in OGC Simple Features SQL style but that won't bring you far. The attribute file you can open with Openoffice or Excel and look at it or export to another format.

share|improve this answer

shapefiles tend to come with several 'companion' files with different extensions. If you just want to extract the attributes, then copying the contents of the .dbf file is sufficient. However, if you want to restore the spatial information, then you will need to add the XY coords into the attribute table first (e.g. AddXY function in ArcMap), then export the attribute table.

share|improve this answer

Your Answer

 
discard

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