How can I convert a shapefile (GIS) to text, or, how can I extract the information in a shapefile?
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.
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.points
Points will contain all the points of the shape at index 0.
If you have ArcGIS 9.x you can use an out of the box script available from ArcToolbox located here, under the ArcGIS install location:
Toolboxes\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...
There is also an ArcGIS Idea called Generate and Ungenerate all vector feature classes from/to ASCII that could use your vote, and this comment has been made:
I just found out at http://forums.arcgis.com/threads/57600-Where-is-the-Generate-tool-in-ArcGIS-10?p=199524#post199524 that there were equivalent tools that already do this in the Sample Tools that have been deprecated (see http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/An_overview_of_the_Samples_toolbox/00pv00000003000000/). Their names are Create Features from Text File and Write Text File from Features.
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.
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.
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.
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