Want to generate a point layer, that contains the maximum points in a polygon layer. all points should have the distance of 6 meters between each other. how can i do it?
[GIS] How to create a point grid within a polygon layer
arcgis-10.0
Related Solutions
Since celticflute did not post his code, I had to figure it out again.
Finally got a working sample. This seems to work pretty well.
The key thing is that you do not write polygon parts and holes differently!
Instead, you construct a polygon from nested arrays which represent parts made of up rings. When you write the geometry by writing it to a shape field or use it in a tool, behind the scenes arc objects planarizes the rings within in each polygon part and determines what's a hole and what isn't. And sorts the coordinates clockwise, and burns the xys into the coordinate system and domain of the geodatabase feature class.
#
# Write a polygon feature class
#
import os
import arcpy
from arcpy import env
def makepoly(coord_list, SR=None):
"""Convert a Python list of coordinates to an ArcPy polygon feature
Author: Curtis Price, USGS, cprice@usgs.gov
Examples, from Desktop Help 10.x: Reading Geometries
Feat0 = [
[[3.0, 8.0],
[1.0, 8.0],
[2.0, 10.0],
[3.0, 8.0]]
]
Feat1 = [
[[5.0, 3.0],
[3.0, 3.0],
[3.0, 5.0],
[5.0, 3.0]],
[[7.0, 5.0],
[5.0, 5.0],
[5.0, 7.0],
[7.0, 5.0]],
]
# this feature has an interior ring (donut)
Feat2 = [
[[9.0, 11.0],
[9.0, 8.0],
[6.0, 8.0],
[6.0, 11.0],
[9.0, 11.0],
None,
[7.0, 10.0],
[7.0, 9.0],
[8.0, 9.0],
[8.0, 10.0],
[7.0, 10.0]]
]
"""
parts = arcpy.Array()
rings = arcpy.Array()
ring = arcpy.Array()
for part in coord_list:
for pnt in part:
if pnt:
ring.add(arcpy.Point(pnt[0], pnt[1]))
else:
# null point - we are at the start of a new ring
rings.add(ring)
ring.removeAll()
# we have our last ring, add it
rings.add(ring)
ring.removeAll()
# if we only have one ring: remove nesting
if len(rings) == 1:
rings = rings.getObject(0)
parts.add(rings)
rings.removeAll()
# if single-part (only one part) remove nesting
if len(parts) == 1:
parts = parts.getObject(0)
return arcpy.Polygon(parts, SR)
# test data from:
# Desktop Help 10.0: Reading Geometries
Feat0 = [
[[3.0, 8.0],
[1.0, 8.0],
[2.0, 10.0],
[3.0, 8.0]]
]
Feat1 = [
[[5.0, 3.0],
[3.0, 3.0],
[3.0, 5.0],
[5.0, 3.0]],
[[7.0, 5.0],
[5.0, 5.0],
[5.0, 7.0],
[7.0, 5.0]],
]
# this last feature has an interior ring (donut)
Feat2 = [
[[9.0, 11.0],
[9.0, 8.0],
[6.0, 8.0],
[6.0, 11.0],
[9.0, 11.0],
None,
[7.0, 10.0],
[7.0, 9.0],
[8.0, 9.0],
[8.0, 10.0],
[7.0, 10.0]]
]
# test code
# create the empty feature class
# with real data, provide a SR code, name or dataset for SR
# SR = arcpy.SpatialReference(4326)
SR = None
env.workspace = env.scratchGDB
Data = arcpy.CreateScratchName("","","featureclass",env.workspace)
print "writing: " + Data
print
arcpy.CreateFeatureclass_management(os.path.dirname(Data),
os.path.basename(Data),"Polygon",
spatial_reference=SR)
# create the polygons and write them
Rows = arcpy.da.InsertCursor(Data, "SHAPE@")
for f in [Feat0, Feat1, Feat2]:
print "coords: " + repr(f)
p = makepoly(f)
print "feature: " + repr(p)
Rows.insertRow([p])
del Rows
It sounds to me that you would get an answer to your question by creating a subset of your points dataset and running Near analysis (if you're using ArcGIS) on it subset choosing it as both: near and input features. Description of that tool. Having done this you would be able to choose points that have a neighbor in the same dataset within certain distance.
Related Question
- [GIS] How to select polygons containing points
- [GIS] Calculating line segment lengths within polygon using ArcGIS Desktop
- [GIS] Automatically create point based on location of polygon using ArcGIS Desktop
- [GIS] How to use a polygon grid to calculate statistics on line and point features
- ArcGIS Desktop – Fill Polygon with Points for Maximum Density (Bin Packing Problem)
Best Answer
You can use the Fish net tool with 3 x 3 as cell size and set labels parameter to
LABELS
, or use the Feature to point tool with Centroid parameter. then Clip points based on polygon boundary