2

I'm using DotSpatial to aid in processing some geospatial data. I'm using the code below to determine if a point (lat/lon location) is within a polygon contained in the SHP. If the point is in a polygon, I want some of the attributes stored in the DBF associated with the polygon. How do I access the attribute data?

// Reproject the strange shapefile so that it is in latitude/longitude coordinates
wierdShapefile.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984);

// Define the WGS84 Lat Lon point to test
Coordinate test = new Coordinate(longitude, latitude);

foreach (Feature f in wierdShapefile.Features)
{
    Polygon pg = f.BasicGeometry as Polygon;
    if (pg != null)
    {
        if (pg.Contains(new Point(test)))
        {
            ******************************************
            *** Need to access attribute data here ***
            ******************************************

            // If the point is inside one of the polygon features
            return true;
        }
    }
    else
    {
        // If you have a multi-part polygon then this should also handle holes I think
        MultiPolygon polygons = f.BasicGeometry as MultiPolygon;
        if (polygons.Contains(new Point(test)))
        {
            return true;
        }
    }
}

return false;
}
-2

You need to access the corresponding row in the feature class data table, with:

f.dataRow

1
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. A good answer should include an explanation about where and how to use the suggested solution, and details on how it solves the problem. Please edit your answer to include this information. – Midavalo Jun 5 '17 at 18:54

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.