Insert a point into feature class based on another point [arcpy]Automatically update feature class based on...
Go Pregnant or Go Home
Can I use my Chinese passport to enter China after I acquired another citizenship?
Will it be accepted, if there is no ''Main Character" stereotype?
Why Were Madagascar and New Zealand Discovered So Late?
What is the opposite of 'gravitas'?
Ways to speed up user implemented RK4
How will losing mobility of one hand affect my career as a programmer?
Displaying the order of the columns of a table
What is the oldest known work of fiction?
How do I keep an essay about "feeling flat" from feeling flat?
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
Is HostGator storing my password in plaintext?
Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past
What is difference between behavior and behaviour
How do I rename a LINUX host without needing to reboot for the rename to take effect?
Coordinate position not precise
Using parameter substitution on a Bash array
Is exact Kanji stroke length important?
Why are on-board computers allowed to change controls without notifying the pilots?
Efficiently merge handle parallel feature branches in SFDX
How does residential electricity work?
Curses work by shouting - How to avoid collateral damage?
Is there a good way to store credentials outside of a password manager?
At which point does a character regain all their Hit Dice?
Insert a point into feature class based on another point [arcpy]
Automatically update feature class based on another feature class in same geodatabaseAssigning an NTA code to a point feature class from a polygon feature classAdding field values from feature class into empty field of another feature class using appendCreating new feature class based on x- and y- coordinates?Using Update Cursor to update all fields in a feature class based upon another feature classCannot insert data into my feature classWhich is the faster way to copy data to another feature class: Feature Class to Feature Class or Insert CursorHow to insert a single point feature into a shapefile?Point feature class showing up empty?Write a script to create a new feature class and add the point objects of geometry to that feature class
My assignment is to insert (using insertCursor) a new city at 0.02 decimal degrees east and 0.03 decimal degrees south of another city. The cities shapfile did not originally have x-y coordinate fields; I added them manually and only for the latter city. However, I'm still not able to use SHAPE@XY or to even print the x-y coordinates on which the new point will be based.
I've been calling the old city based on its FID (1942), but I'm utterly lost on how to use it to add the new city.
Also, in my code, are the mxd, df, and ll objects necessary, or is it enough to call the shapefile using the featureclass object?
arcpy point cursor
New contributor
add a comment |
My assignment is to insert (using insertCursor) a new city at 0.02 decimal degrees east and 0.03 decimal degrees south of another city. The cities shapfile did not originally have x-y coordinate fields; I added them manually and only for the latter city. However, I'm still not able to use SHAPE@XY or to even print the x-y coordinates on which the new point will be based.
I've been calling the old city based on its FID (1942), but I'm utterly lost on how to use it to add the new city.
Also, in my code, are the mxd, df, and ll objects necessary, or is it enough to call the shapefile using the featureclass object?
arcpy point cursor
New contributor
1
Please paste code as text, it makes it easier for us to copy and modify rather than retyping the whole thing. Everything before featureclass= is superfluous, it's not being used but will result in repetition. It's probably not working because you need to add 'r' in front of your feature class full path or double the backslashes (backslash is the escape char).
– Michael Stimson
28 mins ago
add a comment |
My assignment is to insert (using insertCursor) a new city at 0.02 decimal degrees east and 0.03 decimal degrees south of another city. The cities shapfile did not originally have x-y coordinate fields; I added them manually and only for the latter city. However, I'm still not able to use SHAPE@XY or to even print the x-y coordinates on which the new point will be based.
I've been calling the old city based on its FID (1942), but I'm utterly lost on how to use it to add the new city.
Also, in my code, are the mxd, df, and ll objects necessary, or is it enough to call the shapefile using the featureclass object?
arcpy point cursor
New contributor
My assignment is to insert (using insertCursor) a new city at 0.02 decimal degrees east and 0.03 decimal degrees south of another city. The cities shapfile did not originally have x-y coordinate fields; I added them manually and only for the latter city. However, I'm still not able to use SHAPE@XY or to even print the x-y coordinates on which the new point will be based.
I've been calling the old city based on its FID (1942), but I'm utterly lost on how to use it to add the new city.
Also, in my code, are the mxd, df, and ll objects necessary, or is it enough to call the shapefile using the featureclass object?
arcpy point cursor
arcpy point cursor
New contributor
New contributor
edited 6 mins ago
andm
New contributor
asked 32 mins ago
andmandm
11
11
New contributor
New contributor
1
Please paste code as text, it makes it easier for us to copy and modify rather than retyping the whole thing. Everything before featureclass= is superfluous, it's not being used but will result in repetition. It's probably not working because you need to add 'r' in front of your feature class full path or double the backslashes (backslash is the escape char).
– Michael Stimson
28 mins ago
add a comment |
1
Please paste code as text, it makes it easier for us to copy and modify rather than retyping the whole thing. Everything before featureclass= is superfluous, it's not being used but will result in repetition. It's probably not working because you need to add 'r' in front of your feature class full path or double the backslashes (backslash is the escape char).
– Michael Stimson
28 mins ago
1
1
Please paste code as text, it makes it easier for us to copy and modify rather than retyping the whole thing. Everything before featureclass= is superfluous, it's not being used but will result in repetition. It's probably not working because you need to add 'r' in front of your feature class full path or double the backslashes (backslash is the escape char).
– Michael Stimson
28 mins ago
Please paste code as text, it makes it easier for us to copy and modify rather than retyping the whole thing. Everything before featureclass= is superfluous, it's not being used but will result in repetition. It's probably not working because you need to add 'r' in front of your feature class full path or double the backslashes (backslash is the escape char).
– Michael Stimson
28 mins ago
add a comment |
1 Answer
1
active
oldest
votes
Consider something like this, using the where clause of the search cursor to limit the cursor to just the one row:
featureclass = r'e:SchoolworkGEOGGEOG5590HomeworkHomework3CITIES.shp'
# search cursor with just the FID you want, btw it's bad to rely on FIDs
# in a shapefile as they have a habit of changing
with arcpy.da.SeachCursor(featureclass,'SHAPE@XY','FID = 1942') as SCur:
for row in SCur:
XY = row[0] # xy is a tuple (X,Y) to use later
break # done the first one, now break out
# BIG assumption that the data is geographic CRS
with arcpy.da.UpdateCursor(featureclass,'SHAPE@XY') as ICur:
# adjust the values
newX = XY[0] + 0.02
newY = XY[1] - 0.03
ICur.insertRow(((newX,newY))) # insert the tuple of the new X and Y
This assumes you want to insert your new city into the same feature class you sourced the original from and that your data is already geographical. The SHAPE@XY token returns a tuple (X,Y) but you could also use ['SHAPE@X','SHAPE@Y']
which would make your insertRow((newX,newY))
as you're inserting the row as a tuple of values.
Lists can be used instead of tuples, see the examples, as it tends to make it easier to understand whether you're closing the statement, row or tuple:
ICur.insertRow([(newX,newY)]) # insert the tuple of the new X and Y
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
});
}
});
andm is a new contributor. Be nice, and check out our Code of Conduct.
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%2f316788%2finsert-a-point-into-feature-class-based-on-another-point-arcpy%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Consider something like this, using the where clause of the search cursor to limit the cursor to just the one row:
featureclass = r'e:SchoolworkGEOGGEOG5590HomeworkHomework3CITIES.shp'
# search cursor with just the FID you want, btw it's bad to rely on FIDs
# in a shapefile as they have a habit of changing
with arcpy.da.SeachCursor(featureclass,'SHAPE@XY','FID = 1942') as SCur:
for row in SCur:
XY = row[0] # xy is a tuple (X,Y) to use later
break # done the first one, now break out
# BIG assumption that the data is geographic CRS
with arcpy.da.UpdateCursor(featureclass,'SHAPE@XY') as ICur:
# adjust the values
newX = XY[0] + 0.02
newY = XY[1] - 0.03
ICur.insertRow(((newX,newY))) # insert the tuple of the new X and Y
This assumes you want to insert your new city into the same feature class you sourced the original from and that your data is already geographical. The SHAPE@XY token returns a tuple (X,Y) but you could also use ['SHAPE@X','SHAPE@Y']
which would make your insertRow((newX,newY))
as you're inserting the row as a tuple of values.
Lists can be used instead of tuples, see the examples, as it tends to make it easier to understand whether you're closing the statement, row or tuple:
ICur.insertRow([(newX,newY)]) # insert the tuple of the new X and Y
add a comment |
Consider something like this, using the where clause of the search cursor to limit the cursor to just the one row:
featureclass = r'e:SchoolworkGEOGGEOG5590HomeworkHomework3CITIES.shp'
# search cursor with just the FID you want, btw it's bad to rely on FIDs
# in a shapefile as they have a habit of changing
with arcpy.da.SeachCursor(featureclass,'SHAPE@XY','FID = 1942') as SCur:
for row in SCur:
XY = row[0] # xy is a tuple (X,Y) to use later
break # done the first one, now break out
# BIG assumption that the data is geographic CRS
with arcpy.da.UpdateCursor(featureclass,'SHAPE@XY') as ICur:
# adjust the values
newX = XY[0] + 0.02
newY = XY[1] - 0.03
ICur.insertRow(((newX,newY))) # insert the tuple of the new X and Y
This assumes you want to insert your new city into the same feature class you sourced the original from and that your data is already geographical. The SHAPE@XY token returns a tuple (X,Y) but you could also use ['SHAPE@X','SHAPE@Y']
which would make your insertRow((newX,newY))
as you're inserting the row as a tuple of values.
Lists can be used instead of tuples, see the examples, as it tends to make it easier to understand whether you're closing the statement, row or tuple:
ICur.insertRow([(newX,newY)]) # insert the tuple of the new X and Y
add a comment |
Consider something like this, using the where clause of the search cursor to limit the cursor to just the one row:
featureclass = r'e:SchoolworkGEOGGEOG5590HomeworkHomework3CITIES.shp'
# search cursor with just the FID you want, btw it's bad to rely on FIDs
# in a shapefile as they have a habit of changing
with arcpy.da.SeachCursor(featureclass,'SHAPE@XY','FID = 1942') as SCur:
for row in SCur:
XY = row[0] # xy is a tuple (X,Y) to use later
break # done the first one, now break out
# BIG assumption that the data is geographic CRS
with arcpy.da.UpdateCursor(featureclass,'SHAPE@XY') as ICur:
# adjust the values
newX = XY[0] + 0.02
newY = XY[1] - 0.03
ICur.insertRow(((newX,newY))) # insert the tuple of the new X and Y
This assumes you want to insert your new city into the same feature class you sourced the original from and that your data is already geographical. The SHAPE@XY token returns a tuple (X,Y) but you could also use ['SHAPE@X','SHAPE@Y']
which would make your insertRow((newX,newY))
as you're inserting the row as a tuple of values.
Lists can be used instead of tuples, see the examples, as it tends to make it easier to understand whether you're closing the statement, row or tuple:
ICur.insertRow([(newX,newY)]) # insert the tuple of the new X and Y
Consider something like this, using the where clause of the search cursor to limit the cursor to just the one row:
featureclass = r'e:SchoolworkGEOGGEOG5590HomeworkHomework3CITIES.shp'
# search cursor with just the FID you want, btw it's bad to rely on FIDs
# in a shapefile as they have a habit of changing
with arcpy.da.SeachCursor(featureclass,'SHAPE@XY','FID = 1942') as SCur:
for row in SCur:
XY = row[0] # xy is a tuple (X,Y) to use later
break # done the first one, now break out
# BIG assumption that the data is geographic CRS
with arcpy.da.UpdateCursor(featureclass,'SHAPE@XY') as ICur:
# adjust the values
newX = XY[0] + 0.02
newY = XY[1] - 0.03
ICur.insertRow(((newX,newY))) # insert the tuple of the new X and Y
This assumes you want to insert your new city into the same feature class you sourced the original from and that your data is already geographical. The SHAPE@XY token returns a tuple (X,Y) but you could also use ['SHAPE@X','SHAPE@Y']
which would make your insertRow((newX,newY))
as you're inserting the row as a tuple of values.
Lists can be used instead of tuples, see the examples, as it tends to make it easier to understand whether you're closing the statement, row or tuple:
ICur.insertRow([(newX,newY)]) # insert the tuple of the new X and Y
answered 16 mins ago
Michael StimsonMichael Stimson
21.7k22460
21.7k22460
add a comment |
add a comment |
andm is a new contributor. Be nice, and check out our Code of Conduct.
andm is a new contributor. Be nice, and check out our Code of Conduct.
andm is a new contributor. Be nice, and check out our Code of Conduct.
andm is a new contributor. Be nice, and check out our Code of Conduct.
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%2f316788%2finsert-a-point-into-feature-class-based-on-another-point-arcpy%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
1
Please paste code as text, it makes it easier for us to copy and modify rather than retyping the whole thing. Everything before featureclass= is superfluous, it's not being used but will result in repetition. It's probably not working because you need to add 'r' in front of your feature class full path or double the backslashes (backslash is the escape char).
– Michael Stimson
28 mins ago