Select to view content in your preferred language

calculate central point feature within each grid cell.?

1977
7
Jump to solution
02-06-2014 06:39 AM
YamMagar
Deactivated User
Hello,

I have points scattered over grid cell (fishnet), would like to calculate a central point for each cell. How do I do it simpler way in python?

Thanks.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaChisholm
Frequent Contributor
Ohhh, now I get it (i think).

You should be able to do that with two tools. You can do this with or without python.


  1. First, you want to do a spatial join to get the polygon grid data to a point level.


    • Target Features: point data (you can point to either the feature class of the feature layer)

    • Join Features: grid (fishnet) data (you can point to either the feature class of the feature layer)

    • Output Feature class: pick a location

    • Join Operation: JOIN_ONE_TO_MANY (there can be many points inside each grid)

    • Uncheck the "Keep All Target Features" (we don't want to calculate the central point for points that don't fall into a grid)

In python you would use this line:
arcpy.SpatialJoin_analysis(r"C:\Path\To\Points.shp",r"C:\Path\To\Grid.shp",r"C:\Path\To\PointsWithGridData.shp","JOIN_ONE_TO_MANY","KEEP_COMMON")

  • Secondly, use Mean Center tool to get your central points.


    • Input Feature Class: The feature class you created above (you can point to either the feature class of the feature layer)

    • Output Feature Class: pick a location

    • Case Field: pick a unique field from the grid feature class. If you have a grid name field, choose that one. If you can't find one, you can just choose 'JOIN_FID'. 'JOIN_FID' will work but will mean the resulting points will only have a number to be identified/labeled by.

    In python you would use this line:
    arcpy.MeanCenter_stats(r"C:\Path\To\PointsWithGridData.shp",r"C:\Path\To\CentralPoints.shp","#","JOIN_FID")


    Let me know if it works. Good luck!

    View solution in original post

    0 Kudos
    7 Replies
    JoshuaChisholm
    Frequent Contributor
    Hello Milan,

    What format is your grid (fishnet) in? Polygons? Raster? Polylines?

    If your grid is a series of separate polygons you can check out the Feature To Point tool. This tool can be used in python, model builder or run manually.

    Python:
    import arcpy
    inFC=r"C:\Path\To\Grid.shp"
    outFC=r"C:\Path\To\NewPoints.shp"
    arcpy.FeatureToPoint_management(inFC,outFC)
    


    Let me know how it goes!
    ~Josh
    0 Kudos
    YamMagar
    Deactivated User
    Hi Josh,

    Thanks for your tips. Looks like it creates a centroid, but I am expecting a mean point for each cell out of multiple points within a cell. Fishnet is a polygon (vector). Thanks.

    [ATTACH=CONFIG]31182[/ATTACH]
    0 Kudos
    JoshuaChisholm
    Frequent Contributor
    Ok, I think I understand what you're trying to do now. Let me make sure I got it right:
    You want to somehow merge all the points within a given grid to one central point (based on the containing grid).

    Next question: how do you want to combine the fields of all those points into one?
    For example, if a grid has three points and those points have the values of 11, 74 and 36; should the central point have a value of 121 (sum), 40.333 (average), 36 (median) or something different? If there are string fields, how do you want to handle those?

    We should be able to do everything with python.
    0 Kudos
    YamMagar
    Deactivated User
    Thanks for your follow up, really appreciated !. These points are nothing to do with weight, they are just Lat/Long points feature. I just want to calculate a central point based on their location within a grid. Some grids just have one point which is fine ( I want to leave them as they are), but would like to calculate a central point for those grids that has more then one point.
    0 Kudos
    DarrenWiens2
    MVP Alum
    1.) Spatial Join to assign grid ID to points
    2.) Mean Center (case = grid ID)
    0 Kudos
    JoshuaChisholm
    Frequent Contributor
    Ohhh, now I get it (i think).

    You should be able to do that with two tools. You can do this with or without python.


    1. First, you want to do a spatial join to get the polygon grid data to a point level.


      • Target Features: point data (you can point to either the feature class of the feature layer)

      • Join Features: grid (fishnet) data (you can point to either the feature class of the feature layer)

      • Output Feature class: pick a location

      • Join Operation: JOIN_ONE_TO_MANY (there can be many points inside each grid)

      • Uncheck the "Keep All Target Features" (we don't want to calculate the central point for points that don't fall into a grid)

    In python you would use this line:
    arcpy.SpatialJoin_analysis(r"C:\Path\To\Points.shp",r"C:\Path\To\Grid.shp",r"C:\Path\To\PointsWithGridData.shp","JOIN_ONE_TO_MANY","KEEP_COMMON")

  • Secondly, use Mean Center tool to get your central points.


    • Input Feature Class: The feature class you created above (you can point to either the feature class of the feature layer)

    • Output Feature Class: pick a location

    • Case Field: pick a unique field from the grid feature class. If you have a grid name field, choose that one. If you can't find one, you can just choose 'JOIN_FID'. 'JOIN_FID' will work but will mean the resulting points will only have a number to be identified/labeled by.

    In python you would use this line:
    arcpy.MeanCenter_stats(r"C:\Path\To\PointsWithGridData.shp",r"C:\Path\To\CentralPoints.shp","#","JOIN_FID")


    Let me know if it works. Good luck!
    0 Kudos
    YamMagar
    Deactivated User
    Thank you Darren and Josh ! It worked well.
    0 Kudos