I have a Shapefile with several shapes inside it.

Using MapWindow I have been able to determine that the shape I need is the one with shapeId 19.

As you can probably tell I have very little experience with GIS in general but I think I have come to the right place to ask for help.

What I need is to extract all the lat/long coordinates that determine the shape.

Is it possible to do this using MapWindow or do I need to use some other software?

If more information is needed to help, please comment and I will update as soon as possible.

Any help is appreciated as this is driving me crazy!


QGIS can help. Check this answer (the WKT part) to a similar question: Converting tax map polygons from Shapefile to table of map number and corner coordinates

  • Thank you! I am downloading QGIS right now and I will comment back on the results! – Zebs Mar 4 '11 at 20:19
  • It was very easy copying to a text editor. My complementary question is how to convert the points to lat,long infomration? – Zebs Mar 4 '11 at 21:07
  • 2
    Open the original shapefile. Right-click it in the legend and selecct "Save as ...". Chose a target file name and coordinate system EPSG:4326 (WGS84). Load that new shapefile. Now you can get lat/lon coordinates. – underdark Mar 4 '11 at 22:35
  • Thanks, do you know how I can convert the X, Y values to lon/lat. I undertand that I need the projection but I can get that from the shapefile right? – Zebs Mar 4 '11 at 22:35
  • @zebs Yes, I do know; no, you can't do it the way you think. The shapefile contains coordinates and attributes only; no metadata. Sometimes the projection information appears in a .prj file (sharing the base name of the shapefile). If not, then you just gotta know. (The data provider should tell you.) You need GIS software, or the equivalent, to unproject the coordinates. This means converting the shapefile within the GIS into another shapefile (or the equivalent) and then exporting its new coordinates. – whuber Mar 4 '11 at 22:54

Below is a way to access ESRI shapefile latitude and longitude coordinates, among other bits of information such as, spatial reference, field attributes, field values, etc., using Python. The code below only works for polygons and points (because I haven't gotten around to writing the code for polylines). I basically cobbled together some code I found scattered around the ArcGIS Desktop Help 9.3, added some of my own and put it together in one function. It is was written with ArcGIS 9.3. You should be able to pass in a polygon shapefile or point shapefile and the logic will direct it accordingly.

 def get_shapefile( shape_file ):
    # Import native arcgisscripting module
    import arcgisscripting

    # Create the geoprocessor object
    gp = arcgisscripting.create(9.3)

    # Identify the geometry field
    desc = gp.Describe( shape_file )
    shapefieldname = desc.ShapeFieldName

    # Get shapefile Name
    print 'Shapefile Name: ', desc.Name

    # Get the spatial reference
    spatial_reference = desc.SpatialReference.Name
    print 'Spatial Reference: ', spatial_reference

    # Create search cursor
    rows = gp.SearchCursor( shape_file )
    row = rows.Next()

    # Enter while loop for each feature/row
    while row:

        # Create the geometry object
        feat = row.GetValue(shapefieldname)

        print '*' * 30

        print 'Geometry related Information'
        # Get Geometry Type
        geometry_Type = feat.Type
        print 'Geometry Type: ', geometry_Type

        # Get the area of the feature
        geometry_Area = feat.Area
        print 'geometry_Area; ', geometry_Area

        # Get the centroid for the feature
        geometry_Centroid = feat.Centroid
        print 'geometry_Centroid:', geometry_Centroid

        # Get the extent for the feature
        geometry_Extent = feat.Extent
        print 'geometry_extent: ', geometry_Extent

        print 'Get Attribute Table Information'

        # Get all the fields for the feature class
        fields = desc.Fields

        total_number_of_fields = len( fields )
        print 'Total number of fields: ', total_number_of_fields

        print 'List attribute table related information:'

        field_num_cntr = 0

        # Loop through all the fields in the feature class
        for field in fields:

            print '*'*5, field_num_cntr, '*'*5
            print 'field Type: ', field.Type
            print 'Scale: ', str(field.Scale)
            print 'Precision: ', str(field.Precision)
            print field.Name, '=> ', row.GetValue( field.Name )

            field_num_cntr += 1

        if geometry_Type == 'polygon':

            # Variable to keep track of how many multipart polygons are in
            # featureclass
            partnum = 0 

            # Count the number of points in the current multipart feature
            partcount = feat.PartCount

            print 'Number of polygons in feature class: ', partcount

            # Enter while loop for each part in the feature (if a singlepart feature
            # this will occur only once)
            while partnum < partcount:

                # Print the part number
                print "Part ", str(partnum), "of", partcount, ":"
                part = feat.GetPart(partnum)
                pnt = part.Next()

                pntcount = 0

                # Enter while loop for each vertex
                while pnt:

                    # Print x,y coordinates of current point
                    print 'X coord:', pnt.x, 'Y coord:', pnt.y
                    pnt = part.Next()
                    pntcount += 1

                    # If pnt is null, either the part is finished or there is an interior ring
                    if not pnt:
                        pnt = part.Next()
                        if pnt:
                            print "Interior Ring:"
                partnum += 1

                print 'Number of coordinates in feature class: ', pntcount - 1

        elif geometry_Type == 'point':

            feat = row.GetValue(shapefieldname)

            # Get coords
            pnt = feat.GetPart()

            # Print x,y coordinates of current point object
            print 'X coord:', pnt.x, 'Y coord:', pnt.y

        row = rows.Next()

 your_shapefile = 'Path\To\Your\Shapefile.shp'
 get_shapefile( your_shapefile )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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