How can I convert a shape file (GIS) to text?
or, How can I extract the information in a shape file?
|
migrated from superuser.com Mar 16 '11 at 16:01
|
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. |
|||
|
|
|
You can use GDAL/OGR with the ogr2ogr command and export to a csv file, for example:
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. |
|||
|
|
|
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... |
|||
|
|
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:
Shapes will contain an array of shapes
Points will contain all the points of the shape at index 0. |
|||||||
|
|
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. |
|||
|
|
|
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:
On Windows you can easily get a compiled version of ogrinfo by installing FWtools. |
|||
|
|
|
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. |
|||
|
|
|
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. |
|||
|
|
|
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 |
|||
|
|
|
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 |
|||
|
|
|
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 |
|||
|
|
|
load them to PostGIS. query them something like:
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 |
|||
|
|
