Moving / offsetting point locations using ArcPy or ModelBuilder?Mass Updating to Move Points to New Location...
How do we know the LHC results are robust?
How to check is there any negative term in a large list?
How easy is it to start Magic from scratch?
How does it work when somebody invests in my business?
What can we do to stop prior company from asking us questions?
How to pronounce the slash sign
How do I extract a value from a time formatted value in excel?
when is out of tune ok?
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Unreliable Magic - Is it worth it?
How long to clear the 'suck zone' of a turbofan after start is initiated?
Why Were Madagascar and New Zealand Discovered So Late?
How did Arya survive the stabbing?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Trouble understanding the speech of overseas colleagues
India just shot down a satellite from the ground. At what altitude range is the resulting debris field?
How to run a prison with the smallest amount of guards?
You cannot touch me, but I can touch you, who am I?
Customer Requests (Sometimes) Drive Me Bonkers!
Crossing the line between justified force and brutality
How do scammers retract money, while you can’t?
How does Loki do this?
Lay out the Carpet
Method to test if a number is a perfect power?
Moving / offsetting point locations using ArcPy or ModelBuilder?
Mass Updating to Move Points to New Location using ArcPy?Converting Visio diagram to GIS layer for ArcGIS Desktop?Editing coordinates of some point features in ArcGIS 10.3Using well survey data to pinpoint wells from BLM section divisionmoving the objects in a feature class by a field within the table of that feature classDuplicating Features To Create A PatternChanging label placement (anchor point) using ArcPy?Programmatically creating non-feature-linked, simple line callout annotation and setting anchor point?Deriving separate polylines from coded points using ArcObjects (Figure inside)Comparing two geometries in ArcPy?Rotating and moving polygons to different angles using ModelBuilder/ArcPy?Converting Raster datasets into layers using ArcPy/ModelBuilder?Creating single feature to represent group of individual features, based on location and # using ArcGIS Desktop?Using InsertCursor in ModelBuilder?Moving points within ModelBuilder?Exporting Labels to Annotations using ArcPy?Moving shapefiles to folder using ArcMap ModelBuilder?
I have a number non-georeferenced CAD layers (see this question) that have text annotation features. I have created a model to convert the text to points, but after converting the annotation to a Point featureclass, I see that the CAD text anchor points do not coincide with the center of the CAD text (which is where the points belong).
Therefore, I would like to programatically (using ArcPy or ModelBuilder) [move] a feature relative to its current location (delta x,y) using a measured X,Y value that I will provide.
This would allow me to move the GIS points back to where they belong, instead of the offset CAD anchor point.
How can I accomplish this task?
@PolyGeo gave an excellent answer using SHAPE@XY IN 10.1, but currently I am running 10.0. Any 10.0 ideas?
arcpy arcgis-10.0 modelbuilder geometry cursor
add a comment |
I have a number non-georeferenced CAD layers (see this question) that have text annotation features. I have created a model to convert the text to points, but after converting the annotation to a Point featureclass, I see that the CAD text anchor points do not coincide with the center of the CAD text (which is where the points belong).
Therefore, I would like to programatically (using ArcPy or ModelBuilder) [move] a feature relative to its current location (delta x,y) using a measured X,Y value that I will provide.
This would allow me to move the GIS points back to where they belong, instead of the offset CAD anchor point.
How can I accomplish this task?
@PolyGeo gave an excellent answer using SHAPE@XY IN 10.1, but currently I am running 10.0. Any 10.0 ideas?
arcpy arcgis-10.0 modelbuilder geometry cursor
add a comment |
I have a number non-georeferenced CAD layers (see this question) that have text annotation features. I have created a model to convert the text to points, but after converting the annotation to a Point featureclass, I see that the CAD text anchor points do not coincide with the center of the CAD text (which is where the points belong).
Therefore, I would like to programatically (using ArcPy or ModelBuilder) [move] a feature relative to its current location (delta x,y) using a measured X,Y value that I will provide.
This would allow me to move the GIS points back to where they belong, instead of the offset CAD anchor point.
How can I accomplish this task?
@PolyGeo gave an excellent answer using SHAPE@XY IN 10.1, but currently I am running 10.0. Any 10.0 ideas?
arcpy arcgis-10.0 modelbuilder geometry cursor
I have a number non-georeferenced CAD layers (see this question) that have text annotation features. I have created a model to convert the text to points, but after converting the annotation to a Point featureclass, I see that the CAD text anchor points do not coincide with the center of the CAD text (which is where the points belong).
Therefore, I would like to programatically (using ArcPy or ModelBuilder) [move] a feature relative to its current location (delta x,y) using a measured X,Y value that I will provide.
This would allow me to move the GIS points back to where they belong, instead of the offset CAD anchor point.
How can I accomplish this task?
@PolyGeo gave an excellent answer using SHAPE@XY IN 10.1, but currently I am running 10.0. Any 10.0 ideas?
arcpy arcgis-10.0 modelbuilder geometry cursor
arcpy arcgis-10.0 modelbuilder geometry cursor
edited 13 mins ago
RyanDalton
asked Jul 12 '13 at 20:49
RyanDaltonRyanDalton
16.7k1493155
16.7k1493155
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
This code should do it using the SHAPE@XY token that came with arcpy.da.UpdateCursor in ArcGIS 10.1.
import arcpy
# Set some variables
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
# Code to make a copy which will have its coordinates moved (and can be compared with original)
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc,fc2)
# Perform the move
with arcpy.da.UpdateCursor(fc2, ["SHAPE@XY"]) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + xOffset,row[0][1] + yOffset]])
The coding pattern used here came from ArcPy Café.
Ugh! It took me until this morning to realize that SHAPE@XY is only available in 10.1, and my company is still using 10.0. This is a great answer (going forward), but I'm going to wait and see if anyone has any suggestions for 10.0. Thanks!
– RyanDalton
Jul 15 '13 at 14:20
More information on a similar process for anybody reading this. Still 10.1. arcpy.wordpress.com/2013/06/07/disperse-overlapping-points
– theJones
Jul 15 '13 at 15:03
Is this actually setting the values anywhere? Never used the UpdateCursor like that before. Usually I do += and then update the row. Otherwise only thing I do different in my version is the UpdateCursor uses ['SHAPE@X', 'SHAPE@Y'] so you can access them as row[0] and row[1] instead of having to do the row[0][0] and row[0][1]. Think its just a bit easier to read for me.
– eseglem
Jul 15 '13 at 16:03
Yes, that is a valid way to update the rows. Actually, I had never seen a value passed in updateRow() until a few weeks ago. It was actually an example for updating the geometry.
– Paul
Jul 15 '13 at 17:34
Thanks so much for your answer PolyGeo! I was actually pretty impressed that the code worked without modifications. I'm running ArcGIS Desktop 10.6
– Rie Mino
Mar 2 at 2:51
add a comment |
I credit @artwork21 for leading me to my final solution. I actually found a nearly complete script in the ArcGIS 10.0 online help article called "Calculate Field examples", listed under the subcategory "Code samples—geometry" and "For a point feature class, shift the x coordinate of each point by 100"
The final script that I used within the ModelBuilder "Calculate Field" tool was:
Expression:
shiftXYCoordinates(!SHAPE!,%ShiftX%,%ShiftY%)
where ShiftX and ShiftY are variables (as parameters) defined on the ModelBuilder canvas.
Expression Type:
PYTHON_9.3
Code Block:
def shiftXYCoordinates(shape,x_shift,y_shift):
point = shape.getPart(0)
point.X += float(x_shift)
point.Y += float(y_shift)
return point
Since all models work on a selected set, you should also be able to create this as a generic tool that will work in conjunction with other models/tools in other modelbuilder sessions. The very simple model I created (as a "plugin" to other models to shift coordinate values) looks like this. That way I can control the shift on a per-selection-set basis (as defined in other models):
It worked like a charm, thank you all for your input!
is it possible to shift feature by the value inside table, stored in column?
– Losbaltica
Feb 1 '17 at 7:52
1
It should be. Just assign the ShiftX and ShiftY parameters to the appropriate columns.
– RyanDalton
Feb 1 '17 at 18:25
I'm confused by what you are passing in here as "shape". Can you help me out please?
– jbchurchill
May 25 '17 at 20:18
The "Expression" shows the parameters that are being passed into the code-block function called shiftXYCoordinates(). So the first parameter is !SHAPE!, which is the shape field from the layer.
– RyanDalton
May 26 '17 at 15:42
add a comment |
You may also use this field calculator script to move feature locations:
def XYsetVALUE( shape, X_value, Y_value):
myMoveX = 0.001
myMoveY = 0.001
point = shape.getPart(0)
point.X = X_value + myMoveX
point.Y = Y_value + myMoveY
return point
XYsetVALUE ( !SHAPE!, !X_COORD!, !Y_COORD! )
You could include an extra Calculate Field method within your model using the function above.
Thats an interesting way to do it, I didn't actually know you could field calculate on the shape field. This may actually be the easiest way to get it done if it is a set offset for all points. It would probably be faster to do point.X += myMoveX and point.Y += myMoveY instead of needing to pass in X and Y coordinates for it though.
– eseglem
Jul 15 '13 at 15:58
add a comment |
I adapted the solution to move / shift points point into a certain direction (angle) and a given distance.
Looks like:
def shiftXYCoordinates(shape,angle,distance):
point = shape.getPart(0)
point.Y += distance * math.cos(math.radians(angle))
point.X += distance * math.sin(math.radians(angle))
return point
and be called like shiftXYCoordinates(!SHAPE!, !Angle! ,5000), if you have a field “angle” for your points features (or with a constant of course).
Angle should be given in decimal degrees. 0 will shift “up”, 90 “right” etc. I got them after creating strip map index features and converting those to points.
Also make sure to select Field Name “Shape” before running :)
(Solution tested in ArcMap 10.0 SP5)
add a comment |
As you can see, it's a lot easier in 10.1 when you get access to cursor tokens.
import arcpy
# Code to move features in copy of same dataset
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc, fc2)
shape = arcpy.Describe(fc2).ShapeFieldName
cursor = arcpy.UpdateCursor(fc2)
for row in cursor:
point = row.getValue(shape).getPart()
row.setValue(shape, arcpy.Point(point.X + xOffset, point.Y + yOffset))
cursor.updateRow(row)
del point, row, cursor
add a comment |
This works for 10.0:
# Featureclass here
FC = r'featureclass'
fcount = 0
shapefield = arcpy.Describe(FC).shapeFieldName
featureUpdate = arcpy.UpdateCursor(FC)
for f in featureUpdate:
# Hard coded shifts but easy enough to set up a lookup function if needed
sLon = 0.001
sLat = 0.001
# Optional but I like to count to see where it is at in the process
if fcount % 1000 == 0:
print('Updating feature %s...' %(fcount))
# Get the original value
cF = f.getValue(shapefield)
cPNT = cF.getPart()
# Create a new point with the shifted value
sPNT = arcpy.Point(cPNT.X - sLon, cPNT.Y - sLAT)
# Set the shapefield to the new point and update feature
f.setValue(shapefield, sPNT)
featureUpdate.updateRow(f)
fcount += 1
del featureUpdate
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f65959%2fmoving-offsetting-point-locations-using-arcpy-or-modelbuilder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
This code should do it using the SHAPE@XY token that came with arcpy.da.UpdateCursor in ArcGIS 10.1.
import arcpy
# Set some variables
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
# Code to make a copy which will have its coordinates moved (and can be compared with original)
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc,fc2)
# Perform the move
with arcpy.da.UpdateCursor(fc2, ["SHAPE@XY"]) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + xOffset,row[0][1] + yOffset]])
The coding pattern used here came from ArcPy Café.
Ugh! It took me until this morning to realize that SHAPE@XY is only available in 10.1, and my company is still using 10.0. This is a great answer (going forward), but I'm going to wait and see if anyone has any suggestions for 10.0. Thanks!
– RyanDalton
Jul 15 '13 at 14:20
More information on a similar process for anybody reading this. Still 10.1. arcpy.wordpress.com/2013/06/07/disperse-overlapping-points
– theJones
Jul 15 '13 at 15:03
Is this actually setting the values anywhere? Never used the UpdateCursor like that before. Usually I do += and then update the row. Otherwise only thing I do different in my version is the UpdateCursor uses ['SHAPE@X', 'SHAPE@Y'] so you can access them as row[0] and row[1] instead of having to do the row[0][0] and row[0][1]. Think its just a bit easier to read for me.
– eseglem
Jul 15 '13 at 16:03
Yes, that is a valid way to update the rows. Actually, I had never seen a value passed in updateRow() until a few weeks ago. It was actually an example for updating the geometry.
– Paul
Jul 15 '13 at 17:34
Thanks so much for your answer PolyGeo! I was actually pretty impressed that the code worked without modifications. I'm running ArcGIS Desktop 10.6
– Rie Mino
Mar 2 at 2:51
add a comment |
This code should do it using the SHAPE@XY token that came with arcpy.da.UpdateCursor in ArcGIS 10.1.
import arcpy
# Set some variables
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
# Code to make a copy which will have its coordinates moved (and can be compared with original)
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc,fc2)
# Perform the move
with arcpy.da.UpdateCursor(fc2, ["SHAPE@XY"]) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + xOffset,row[0][1] + yOffset]])
The coding pattern used here came from ArcPy Café.
Ugh! It took me until this morning to realize that SHAPE@XY is only available in 10.1, and my company is still using 10.0. This is a great answer (going forward), but I'm going to wait and see if anyone has any suggestions for 10.0. Thanks!
– RyanDalton
Jul 15 '13 at 14:20
More information on a similar process for anybody reading this. Still 10.1. arcpy.wordpress.com/2013/06/07/disperse-overlapping-points
– theJones
Jul 15 '13 at 15:03
Is this actually setting the values anywhere? Never used the UpdateCursor like that before. Usually I do += and then update the row. Otherwise only thing I do different in my version is the UpdateCursor uses ['SHAPE@X', 'SHAPE@Y'] so you can access them as row[0] and row[1] instead of having to do the row[0][0] and row[0][1]. Think its just a bit easier to read for me.
– eseglem
Jul 15 '13 at 16:03
Yes, that is a valid way to update the rows. Actually, I had never seen a value passed in updateRow() until a few weeks ago. It was actually an example for updating the geometry.
– Paul
Jul 15 '13 at 17:34
Thanks so much for your answer PolyGeo! I was actually pretty impressed that the code worked without modifications. I'm running ArcGIS Desktop 10.6
– Rie Mino
Mar 2 at 2:51
add a comment |
This code should do it using the SHAPE@XY token that came with arcpy.da.UpdateCursor in ArcGIS 10.1.
import arcpy
# Set some variables
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
# Code to make a copy which will have its coordinates moved (and can be compared with original)
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc,fc2)
# Perform the move
with arcpy.da.UpdateCursor(fc2, ["SHAPE@XY"]) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + xOffset,row[0][1] + yOffset]])
The coding pattern used here came from ArcPy Café.
This code should do it using the SHAPE@XY token that came with arcpy.da.UpdateCursor in ArcGIS 10.1.
import arcpy
# Set some variables
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
# Code to make a copy which will have its coordinates moved (and can be compared with original)
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc,fc2)
# Perform the move
with arcpy.da.UpdateCursor(fc2, ["SHAPE@XY"]) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + xOffset,row[0][1] + yOffset]])
The coding pattern used here came from ArcPy Café.
edited Nov 26 '17 at 7:28
answered Jul 12 '13 at 23:08
PolyGeo♦PolyGeo
53.8k1781245
53.8k1781245
Ugh! It took me until this morning to realize that SHAPE@XY is only available in 10.1, and my company is still using 10.0. This is a great answer (going forward), but I'm going to wait and see if anyone has any suggestions for 10.0. Thanks!
– RyanDalton
Jul 15 '13 at 14:20
More information on a similar process for anybody reading this. Still 10.1. arcpy.wordpress.com/2013/06/07/disperse-overlapping-points
– theJones
Jul 15 '13 at 15:03
Is this actually setting the values anywhere? Never used the UpdateCursor like that before. Usually I do += and then update the row. Otherwise only thing I do different in my version is the UpdateCursor uses ['SHAPE@X', 'SHAPE@Y'] so you can access them as row[0] and row[1] instead of having to do the row[0][0] and row[0][1]. Think its just a bit easier to read for me.
– eseglem
Jul 15 '13 at 16:03
Yes, that is a valid way to update the rows. Actually, I had never seen a value passed in updateRow() until a few weeks ago. It was actually an example for updating the geometry.
– Paul
Jul 15 '13 at 17:34
Thanks so much for your answer PolyGeo! I was actually pretty impressed that the code worked without modifications. I'm running ArcGIS Desktop 10.6
– Rie Mino
Mar 2 at 2:51
add a comment |
Ugh! It took me until this morning to realize that SHAPE@XY is only available in 10.1, and my company is still using 10.0. This is a great answer (going forward), but I'm going to wait and see if anyone has any suggestions for 10.0. Thanks!
– RyanDalton
Jul 15 '13 at 14:20
More information on a similar process for anybody reading this. Still 10.1. arcpy.wordpress.com/2013/06/07/disperse-overlapping-points
– theJones
Jul 15 '13 at 15:03
Is this actually setting the values anywhere? Never used the UpdateCursor like that before. Usually I do += and then update the row. Otherwise only thing I do different in my version is the UpdateCursor uses ['SHAPE@X', 'SHAPE@Y'] so you can access them as row[0] and row[1] instead of having to do the row[0][0] and row[0][1]. Think its just a bit easier to read for me.
– eseglem
Jul 15 '13 at 16:03
Yes, that is a valid way to update the rows. Actually, I had never seen a value passed in updateRow() until a few weeks ago. It was actually an example for updating the geometry.
– Paul
Jul 15 '13 at 17:34
Thanks so much for your answer PolyGeo! I was actually pretty impressed that the code worked without modifications. I'm running ArcGIS Desktop 10.6
– Rie Mino
Mar 2 at 2:51
Ugh! It took me until this morning to realize that SHAPE@XY is only available in 10.1, and my company is still using 10.0. This is a great answer (going forward), but I'm going to wait and see if anyone has any suggestions for 10.0. Thanks!
– RyanDalton
Jul 15 '13 at 14:20
Ugh! It took me until this morning to realize that SHAPE@XY is only available in 10.1, and my company is still using 10.0. This is a great answer (going forward), but I'm going to wait and see if anyone has any suggestions for 10.0. Thanks!
– RyanDalton
Jul 15 '13 at 14:20
More information on a similar process for anybody reading this. Still 10.1. arcpy.wordpress.com/2013/06/07/disperse-overlapping-points
– theJones
Jul 15 '13 at 15:03
More information on a similar process for anybody reading this. Still 10.1. arcpy.wordpress.com/2013/06/07/disperse-overlapping-points
– theJones
Jul 15 '13 at 15:03
Is this actually setting the values anywhere? Never used the UpdateCursor like that before. Usually I do += and then update the row. Otherwise only thing I do different in my version is the UpdateCursor uses ['SHAPE@X', 'SHAPE@Y'] so you can access them as row[0] and row[1] instead of having to do the row[0][0] and row[0][1]. Think its just a bit easier to read for me.
– eseglem
Jul 15 '13 at 16:03
Is this actually setting the values anywhere? Never used the UpdateCursor like that before. Usually I do += and then update the row. Otherwise only thing I do different in my version is the UpdateCursor uses ['SHAPE@X', 'SHAPE@Y'] so you can access them as row[0] and row[1] instead of having to do the row[0][0] and row[0][1]. Think its just a bit easier to read for me.
– eseglem
Jul 15 '13 at 16:03
Yes, that is a valid way to update the rows. Actually, I had never seen a value passed in updateRow() until a few weeks ago. It was actually an example for updating the geometry.
– Paul
Jul 15 '13 at 17:34
Yes, that is a valid way to update the rows. Actually, I had never seen a value passed in updateRow() until a few weeks ago. It was actually an example for updating the geometry.
– Paul
Jul 15 '13 at 17:34
Thanks so much for your answer PolyGeo! I was actually pretty impressed that the code worked without modifications. I'm running ArcGIS Desktop 10.6
– Rie Mino
Mar 2 at 2:51
Thanks so much for your answer PolyGeo! I was actually pretty impressed that the code worked without modifications. I'm running ArcGIS Desktop 10.6
– Rie Mino
Mar 2 at 2:51
add a comment |
I credit @artwork21 for leading me to my final solution. I actually found a nearly complete script in the ArcGIS 10.0 online help article called "Calculate Field examples", listed under the subcategory "Code samples—geometry" and "For a point feature class, shift the x coordinate of each point by 100"
The final script that I used within the ModelBuilder "Calculate Field" tool was:
Expression:
shiftXYCoordinates(!SHAPE!,%ShiftX%,%ShiftY%)
where ShiftX and ShiftY are variables (as parameters) defined on the ModelBuilder canvas.
Expression Type:
PYTHON_9.3
Code Block:
def shiftXYCoordinates(shape,x_shift,y_shift):
point = shape.getPart(0)
point.X += float(x_shift)
point.Y += float(y_shift)
return point
Since all models work on a selected set, you should also be able to create this as a generic tool that will work in conjunction with other models/tools in other modelbuilder sessions. The very simple model I created (as a "plugin" to other models to shift coordinate values) looks like this. That way I can control the shift on a per-selection-set basis (as defined in other models):
It worked like a charm, thank you all for your input!
is it possible to shift feature by the value inside table, stored in column?
– Losbaltica
Feb 1 '17 at 7:52
1
It should be. Just assign the ShiftX and ShiftY parameters to the appropriate columns.
– RyanDalton
Feb 1 '17 at 18:25
I'm confused by what you are passing in here as "shape". Can you help me out please?
– jbchurchill
May 25 '17 at 20:18
The "Expression" shows the parameters that are being passed into the code-block function called shiftXYCoordinates(). So the first parameter is !SHAPE!, which is the shape field from the layer.
– RyanDalton
May 26 '17 at 15:42
add a comment |
I credit @artwork21 for leading me to my final solution. I actually found a nearly complete script in the ArcGIS 10.0 online help article called "Calculate Field examples", listed under the subcategory "Code samples—geometry" and "For a point feature class, shift the x coordinate of each point by 100"
The final script that I used within the ModelBuilder "Calculate Field" tool was:
Expression:
shiftXYCoordinates(!SHAPE!,%ShiftX%,%ShiftY%)
where ShiftX and ShiftY are variables (as parameters) defined on the ModelBuilder canvas.
Expression Type:
PYTHON_9.3
Code Block:
def shiftXYCoordinates(shape,x_shift,y_shift):
point = shape.getPart(0)
point.X += float(x_shift)
point.Y += float(y_shift)
return point
Since all models work on a selected set, you should also be able to create this as a generic tool that will work in conjunction with other models/tools in other modelbuilder sessions. The very simple model I created (as a "plugin" to other models to shift coordinate values) looks like this. That way I can control the shift on a per-selection-set basis (as defined in other models):
It worked like a charm, thank you all for your input!
is it possible to shift feature by the value inside table, stored in column?
– Losbaltica
Feb 1 '17 at 7:52
1
It should be. Just assign the ShiftX and ShiftY parameters to the appropriate columns.
– RyanDalton
Feb 1 '17 at 18:25
I'm confused by what you are passing in here as "shape". Can you help me out please?
– jbchurchill
May 25 '17 at 20:18
The "Expression" shows the parameters that are being passed into the code-block function called shiftXYCoordinates(). So the first parameter is !SHAPE!, which is the shape field from the layer.
– RyanDalton
May 26 '17 at 15:42
add a comment |
I credit @artwork21 for leading me to my final solution. I actually found a nearly complete script in the ArcGIS 10.0 online help article called "Calculate Field examples", listed under the subcategory "Code samples—geometry" and "For a point feature class, shift the x coordinate of each point by 100"
The final script that I used within the ModelBuilder "Calculate Field" tool was:
Expression:
shiftXYCoordinates(!SHAPE!,%ShiftX%,%ShiftY%)
where ShiftX and ShiftY are variables (as parameters) defined on the ModelBuilder canvas.
Expression Type:
PYTHON_9.3
Code Block:
def shiftXYCoordinates(shape,x_shift,y_shift):
point = shape.getPart(0)
point.X += float(x_shift)
point.Y += float(y_shift)
return point
Since all models work on a selected set, you should also be able to create this as a generic tool that will work in conjunction with other models/tools in other modelbuilder sessions. The very simple model I created (as a "plugin" to other models to shift coordinate values) looks like this. That way I can control the shift on a per-selection-set basis (as defined in other models):
It worked like a charm, thank you all for your input!
I credit @artwork21 for leading me to my final solution. I actually found a nearly complete script in the ArcGIS 10.0 online help article called "Calculate Field examples", listed under the subcategory "Code samples—geometry" and "For a point feature class, shift the x coordinate of each point by 100"
The final script that I used within the ModelBuilder "Calculate Field" tool was:
Expression:
shiftXYCoordinates(!SHAPE!,%ShiftX%,%ShiftY%)
where ShiftX and ShiftY are variables (as parameters) defined on the ModelBuilder canvas.
Expression Type:
PYTHON_9.3
Code Block:
def shiftXYCoordinates(shape,x_shift,y_shift):
point = shape.getPart(0)
point.X += float(x_shift)
point.Y += float(y_shift)
return point
Since all models work on a selected set, you should also be able to create this as a generic tool that will work in conjunction with other models/tools in other modelbuilder sessions. The very simple model I created (as a "plugin" to other models to shift coordinate values) looks like this. That way I can control the shift on a per-selection-set basis (as defined in other models):
It worked like a charm, thank you all for your input!
edited May 26 '17 at 15:40
answered Jul 15 '13 at 17:01
RyanDaltonRyanDalton
16.7k1493155
16.7k1493155
is it possible to shift feature by the value inside table, stored in column?
– Losbaltica
Feb 1 '17 at 7:52
1
It should be. Just assign the ShiftX and ShiftY parameters to the appropriate columns.
– RyanDalton
Feb 1 '17 at 18:25
I'm confused by what you are passing in here as "shape". Can you help me out please?
– jbchurchill
May 25 '17 at 20:18
The "Expression" shows the parameters that are being passed into the code-block function called shiftXYCoordinates(). So the first parameter is !SHAPE!, which is the shape field from the layer.
– RyanDalton
May 26 '17 at 15:42
add a comment |
is it possible to shift feature by the value inside table, stored in column?
– Losbaltica
Feb 1 '17 at 7:52
1
It should be. Just assign the ShiftX and ShiftY parameters to the appropriate columns.
– RyanDalton
Feb 1 '17 at 18:25
I'm confused by what you are passing in here as "shape". Can you help me out please?
– jbchurchill
May 25 '17 at 20:18
The "Expression" shows the parameters that are being passed into the code-block function called shiftXYCoordinates(). So the first parameter is !SHAPE!, which is the shape field from the layer.
– RyanDalton
May 26 '17 at 15:42
is it possible to shift feature by the value inside table, stored in column?
– Losbaltica
Feb 1 '17 at 7:52
is it possible to shift feature by the value inside table, stored in column?
– Losbaltica
Feb 1 '17 at 7:52
1
1
It should be. Just assign the ShiftX and ShiftY parameters to the appropriate columns.
– RyanDalton
Feb 1 '17 at 18:25
It should be. Just assign the ShiftX and ShiftY parameters to the appropriate columns.
– RyanDalton
Feb 1 '17 at 18:25
I'm confused by what you are passing in here as "shape". Can you help me out please?
– jbchurchill
May 25 '17 at 20:18
I'm confused by what you are passing in here as "shape". Can you help me out please?
– jbchurchill
May 25 '17 at 20:18
The "Expression" shows the parameters that are being passed into the code-block function called shiftXYCoordinates(). So the first parameter is !SHAPE!, which is the shape field from the layer.
– RyanDalton
May 26 '17 at 15:42
The "Expression" shows the parameters that are being passed into the code-block function called shiftXYCoordinates(). So the first parameter is !SHAPE!, which is the shape field from the layer.
– RyanDalton
May 26 '17 at 15:42
add a comment |
You may also use this field calculator script to move feature locations:
def XYsetVALUE( shape, X_value, Y_value):
myMoveX = 0.001
myMoveY = 0.001
point = shape.getPart(0)
point.X = X_value + myMoveX
point.Y = Y_value + myMoveY
return point
XYsetVALUE ( !SHAPE!, !X_COORD!, !Y_COORD! )
You could include an extra Calculate Field method within your model using the function above.
Thats an interesting way to do it, I didn't actually know you could field calculate on the shape field. This may actually be the easiest way to get it done if it is a set offset for all points. It would probably be faster to do point.X += myMoveX and point.Y += myMoveY instead of needing to pass in X and Y coordinates for it though.
– eseglem
Jul 15 '13 at 15:58
add a comment |
You may also use this field calculator script to move feature locations:
def XYsetVALUE( shape, X_value, Y_value):
myMoveX = 0.001
myMoveY = 0.001
point = shape.getPart(0)
point.X = X_value + myMoveX
point.Y = Y_value + myMoveY
return point
XYsetVALUE ( !SHAPE!, !X_COORD!, !Y_COORD! )
You could include an extra Calculate Field method within your model using the function above.
Thats an interesting way to do it, I didn't actually know you could field calculate on the shape field. This may actually be the easiest way to get it done if it is a set offset for all points. It would probably be faster to do point.X += myMoveX and point.Y += myMoveY instead of needing to pass in X and Y coordinates for it though.
– eseglem
Jul 15 '13 at 15:58
add a comment |
You may also use this field calculator script to move feature locations:
def XYsetVALUE( shape, X_value, Y_value):
myMoveX = 0.001
myMoveY = 0.001
point = shape.getPart(0)
point.X = X_value + myMoveX
point.Y = Y_value + myMoveY
return point
XYsetVALUE ( !SHAPE!, !X_COORD!, !Y_COORD! )
You could include an extra Calculate Field method within your model using the function above.
You may also use this field calculator script to move feature locations:
def XYsetVALUE( shape, X_value, Y_value):
myMoveX = 0.001
myMoveY = 0.001
point = shape.getPart(0)
point.X = X_value + myMoveX
point.Y = Y_value + myMoveY
return point
XYsetVALUE ( !SHAPE!, !X_COORD!, !Y_COORD! )
You could include an extra Calculate Field method within your model using the function above.
answered Jul 15 '13 at 15:26
artwork21artwork21
31.1k554120
31.1k554120
Thats an interesting way to do it, I didn't actually know you could field calculate on the shape field. This may actually be the easiest way to get it done if it is a set offset for all points. It would probably be faster to do point.X += myMoveX and point.Y += myMoveY instead of needing to pass in X and Y coordinates for it though.
– eseglem
Jul 15 '13 at 15:58
add a comment |
Thats an interesting way to do it, I didn't actually know you could field calculate on the shape field. This may actually be the easiest way to get it done if it is a set offset for all points. It would probably be faster to do point.X += myMoveX and point.Y += myMoveY instead of needing to pass in X and Y coordinates for it though.
– eseglem
Jul 15 '13 at 15:58
Thats an interesting way to do it, I didn't actually know you could field calculate on the shape field. This may actually be the easiest way to get it done if it is a set offset for all points. It would probably be faster to do point.X += myMoveX and point.Y += myMoveY instead of needing to pass in X and Y coordinates for it though.
– eseglem
Jul 15 '13 at 15:58
Thats an interesting way to do it, I didn't actually know you could field calculate on the shape field. This may actually be the easiest way to get it done if it is a set offset for all points. It would probably be faster to do point.X += myMoveX and point.Y += myMoveY instead of needing to pass in X and Y coordinates for it though.
– eseglem
Jul 15 '13 at 15:58
add a comment |
I adapted the solution to move / shift points point into a certain direction (angle) and a given distance.
Looks like:
def shiftXYCoordinates(shape,angle,distance):
point = shape.getPart(0)
point.Y += distance * math.cos(math.radians(angle))
point.X += distance * math.sin(math.radians(angle))
return point
and be called like shiftXYCoordinates(!SHAPE!, !Angle! ,5000), if you have a field “angle” for your points features (or with a constant of course).
Angle should be given in decimal degrees. 0 will shift “up”, 90 “right” etc. I got them after creating strip map index features and converting those to points.
Also make sure to select Field Name “Shape” before running :)
(Solution tested in ArcMap 10.0 SP5)
add a comment |
I adapted the solution to move / shift points point into a certain direction (angle) and a given distance.
Looks like:
def shiftXYCoordinates(shape,angle,distance):
point = shape.getPart(0)
point.Y += distance * math.cos(math.radians(angle))
point.X += distance * math.sin(math.radians(angle))
return point
and be called like shiftXYCoordinates(!SHAPE!, !Angle! ,5000), if you have a field “angle” for your points features (or with a constant of course).
Angle should be given in decimal degrees. 0 will shift “up”, 90 “right” etc. I got them after creating strip map index features and converting those to points.
Also make sure to select Field Name “Shape” before running :)
(Solution tested in ArcMap 10.0 SP5)
add a comment |
I adapted the solution to move / shift points point into a certain direction (angle) and a given distance.
Looks like:
def shiftXYCoordinates(shape,angle,distance):
point = shape.getPart(0)
point.Y += distance * math.cos(math.radians(angle))
point.X += distance * math.sin(math.radians(angle))
return point
and be called like shiftXYCoordinates(!SHAPE!, !Angle! ,5000), if you have a field “angle” for your points features (or with a constant of course).
Angle should be given in decimal degrees. 0 will shift “up”, 90 “right” etc. I got them after creating strip map index features and converting those to points.
Also make sure to select Field Name “Shape” before running :)
(Solution tested in ArcMap 10.0 SP5)
I adapted the solution to move / shift points point into a certain direction (angle) and a given distance.
Looks like:
def shiftXYCoordinates(shape,angle,distance):
point = shape.getPart(0)
point.Y += distance * math.cos(math.radians(angle))
point.X += distance * math.sin(math.radians(angle))
return point
and be called like shiftXYCoordinates(!SHAPE!, !Angle! ,5000), if you have a field “angle” for your points features (or with a constant of course).
Angle should be given in decimal degrees. 0 will shift “up”, 90 “right” etc. I got them after creating strip map index features and converting those to points.
Also make sure to select Field Name “Shape” before running :)
(Solution tested in ArcMap 10.0 SP5)
edited Jul 10 '14 at 11:31
PolyGeo♦
53.8k1781245
53.8k1781245
answered Jul 10 '14 at 11:09
kglkgl
5111
5111
add a comment |
add a comment |
As you can see, it's a lot easier in 10.1 when you get access to cursor tokens.
import arcpy
# Code to move features in copy of same dataset
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc, fc2)
shape = arcpy.Describe(fc2).ShapeFieldName
cursor = arcpy.UpdateCursor(fc2)
for row in cursor:
point = row.getValue(shape).getPart()
row.setValue(shape, arcpy.Point(point.X + xOffset, point.Y + yOffset))
cursor.updateRow(row)
del point, row, cursor
add a comment |
As you can see, it's a lot easier in 10.1 when you get access to cursor tokens.
import arcpy
# Code to move features in copy of same dataset
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc, fc2)
shape = arcpy.Describe(fc2).ShapeFieldName
cursor = arcpy.UpdateCursor(fc2)
for row in cursor:
point = row.getValue(shape).getPart()
row.setValue(shape, arcpy.Point(point.X + xOffset, point.Y + yOffset))
cursor.updateRow(row)
del point, row, cursor
add a comment |
As you can see, it's a lot easier in 10.1 when you get access to cursor tokens.
import arcpy
# Code to move features in copy of same dataset
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc, fc2)
shape = arcpy.Describe(fc2).ShapeFieldName
cursor = arcpy.UpdateCursor(fc2)
for row in cursor:
point = row.getValue(shape).getPart()
row.setValue(shape, arcpy.Point(point.X + xOffset, point.Y + yOffset))
cursor.updateRow(row)
del point, row, cursor
As you can see, it's a lot easier in 10.1 when you get access to cursor tokens.
import arcpy
# Code to move features in copy of same dataset
fc = r"C:temptest.gdbtestFC"
fc2 = r"C:temptest.gdbtestFCcopy"
xOffset = 0.001
yOffset = 0.001
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc, fc2)
shape = arcpy.Describe(fc2).ShapeFieldName
cursor = arcpy.UpdateCursor(fc2)
for row in cursor:
point = row.getValue(shape).getPart()
row.setValue(shape, arcpy.Point(point.X + xOffset, point.Y + yOffset))
cursor.updateRow(row)
del point, row, cursor
answered Jul 15 '13 at 15:19
PaulPaul
11k12241
11k12241
add a comment |
add a comment |
This works for 10.0:
# Featureclass here
FC = r'featureclass'
fcount = 0
shapefield = arcpy.Describe(FC).shapeFieldName
featureUpdate = arcpy.UpdateCursor(FC)
for f in featureUpdate:
# Hard coded shifts but easy enough to set up a lookup function if needed
sLon = 0.001
sLat = 0.001
# Optional but I like to count to see where it is at in the process
if fcount % 1000 == 0:
print('Updating feature %s...' %(fcount))
# Get the original value
cF = f.getValue(shapefield)
cPNT = cF.getPart()
# Create a new point with the shifted value
sPNT = arcpy.Point(cPNT.X - sLon, cPNT.Y - sLAT)
# Set the shapefield to the new point and update feature
f.setValue(shapefield, sPNT)
featureUpdate.updateRow(f)
fcount += 1
del featureUpdate
add a comment |
This works for 10.0:
# Featureclass here
FC = r'featureclass'
fcount = 0
shapefield = arcpy.Describe(FC).shapeFieldName
featureUpdate = arcpy.UpdateCursor(FC)
for f in featureUpdate:
# Hard coded shifts but easy enough to set up a lookup function if needed
sLon = 0.001
sLat = 0.001
# Optional but I like to count to see where it is at in the process
if fcount % 1000 == 0:
print('Updating feature %s...' %(fcount))
# Get the original value
cF = f.getValue(shapefield)
cPNT = cF.getPart()
# Create a new point with the shifted value
sPNT = arcpy.Point(cPNT.X - sLon, cPNT.Y - sLAT)
# Set the shapefield to the new point and update feature
f.setValue(shapefield, sPNT)
featureUpdate.updateRow(f)
fcount += 1
del featureUpdate
add a comment |
This works for 10.0:
# Featureclass here
FC = r'featureclass'
fcount = 0
shapefield = arcpy.Describe(FC).shapeFieldName
featureUpdate = arcpy.UpdateCursor(FC)
for f in featureUpdate:
# Hard coded shifts but easy enough to set up a lookup function if needed
sLon = 0.001
sLat = 0.001
# Optional but I like to count to see where it is at in the process
if fcount % 1000 == 0:
print('Updating feature %s...' %(fcount))
# Get the original value
cF = f.getValue(shapefield)
cPNT = cF.getPart()
# Create a new point with the shifted value
sPNT = arcpy.Point(cPNT.X - sLon, cPNT.Y - sLAT)
# Set the shapefield to the new point and update feature
f.setValue(shapefield, sPNT)
featureUpdate.updateRow(f)
fcount += 1
del featureUpdate
This works for 10.0:
# Featureclass here
FC = r'featureclass'
fcount = 0
shapefield = arcpy.Describe(FC).shapeFieldName
featureUpdate = arcpy.UpdateCursor(FC)
for f in featureUpdate:
# Hard coded shifts but easy enough to set up a lookup function if needed
sLon = 0.001
sLat = 0.001
# Optional but I like to count to see where it is at in the process
if fcount % 1000 == 0:
print('Updating feature %s...' %(fcount))
# Get the original value
cF = f.getValue(shapefield)
cPNT = cF.getPart()
# Create a new point with the shifted value
sPNT = arcpy.Point(cPNT.X - sLon, cPNT.Y - sLAT)
# Set the shapefield to the new point and update feature
f.setValue(shapefield, sPNT)
featureUpdate.updateRow(f)
fcount += 1
del featureUpdate
edited Apr 7 '16 at 23:03
PolyGeo♦
53.8k1781245
53.8k1781245
answered Jul 15 '13 at 15:06
eseglemeseglem
500412
500412
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f65959%2fmoving-offsetting-point-locations-using-arcpy-or-modelbuilder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown