Create/Copy features in specific coordinates

2515
3
Jump to solution
03-03-2016 08:52 AM
GastonIzaguirre
New Contributor III

Hi all,

I need to replicate an existing multi-line feature several times (e.g., copy and paste), but not at any random position. The new features should be centered on certain coordinates given by another point feature class. That is, ech new multi-line feature must be centered at each existing point.

INPUTS
1 multi-line feature class, with 1 feature
1 point feature class, with > 1000 points
OUTPUTS
1 multi-line feature class, with > 1000 features (same number as points), each centered at coordinates given by each point

I am using ArcGIS 10.0 SP5.

I hope I was clear enough to describe my problem.

Any suggestion or solution is welcome, either through scripting or using any geoprocessing tool that I have missed.

Thanks in advance.

Gastón.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

Here's how you can do it using Python at 10.1+ (sorry, no data access module at 10.0):

>>> points_fc = 'points' # input points
... template_fc = 'template' # template line feature class
... out_fc = r'C:\junk\outputlines.shp' # output feature class
... sr = arcpy.Describe(points_fc).spatialReference # spatial reference
... template_geom = arcpy.da.SearchCursor(template_fc, 'SHAPE@', spatial_reference=sr).next() # get first line
... lines = [] # temporary line container
... points_count = int(arcpy.GetCount_management(points_fc).getOutput(0)) # count points
... for i in range(points_count):
...     lines.append(template_geom[0]) # create line copies
... arcpy.CopyFeatures_management(lines, out_fc) # write lines to feature class
... points = arcpy.da.SearchCursor(points_fc, 'SHAPE@XY', spatial_reference=sr) # load points to list for later
... with arcpy.da.UpdateCursor(out_fc,['SHAPE@XY'],spatial_reference=sr) as cursor: # loop through line copies, collecting line centroid 
...     for row in cursor:
...         cur_point = points.next() # get next point geometry
...         cursor.updateRow([(cur_point[0][0], cur_point[0][1])]) # move line feature centroid to new location

---->

View solution in original post

3 Replies
WesMiller
Regular Contributor III
DarrenWiens2
MVP Honored Contributor

Here's how you can do it using Python at 10.1+ (sorry, no data access module at 10.0):

>>> points_fc = 'points' # input points
... template_fc = 'template' # template line feature class
... out_fc = r'C:\junk\outputlines.shp' # output feature class
... sr = arcpy.Describe(points_fc).spatialReference # spatial reference
... template_geom = arcpy.da.SearchCursor(template_fc, 'SHAPE@', spatial_reference=sr).next() # get first line
... lines = [] # temporary line container
... points_count = int(arcpy.GetCount_management(points_fc).getOutput(0)) # count points
... for i in range(points_count):
...     lines.append(template_geom[0]) # create line copies
... arcpy.CopyFeatures_management(lines, out_fc) # write lines to feature class
... points = arcpy.da.SearchCursor(points_fc, 'SHAPE@XY', spatial_reference=sr) # load points to list for later
... with arcpy.da.UpdateCursor(out_fc,['SHAPE@XY'],spatial_reference=sr) as cursor: # loop through line copies, collecting line centroid 
...     for row in cursor:
...         cur_point = points.next() # get next point geometry
...         cursor.updateRow([(cur_point[0][0], cur_point[0][1])]) # move line feature centroid to new location

---->

GastonIzaguirre
New Contributor III

Excellent!

That's just what I needed.

It works perfect.

Darren, thank you very much for taking the time for this answer.

0 Kudos