Having problems with creating a new field in a shape file The Next CEO of Stack OverflowWhere...

Is there a difference between "Fahrstuhl" and "Aufzug"

Can we say or write : "No, it'sn't"?

Between two walls

How did the Bene Gesserit know how to make a Kwisatz Haderach?

Extending anchors in TikZ

Does it take more energy to get to Venus or to Mars?

Skipping indices in a product

If the heap is initialized for security, then why is the stack uninitialized?

Elegant way to replace substring in a regex with optional groups in Python?

What happens if you roll doubles 3 times then land on "Go to jail?"

How to start emacs in "nothing" mode (`fundamental-mode`)

multiple labels for a single equation

How did people program for Consoles with multiple CPUs?

Received an invoice from my ex-employer billing me for training; how to handle?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

Is it possible to search for a directory/file combination?

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Can I equip Skullclamp on a creature I am sacrificing?

Is there an analogue of projective spaces for proper schemes?

How should I support this large drywall patch?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

How do I go from 300 unfinished/half written blog posts, to published posts?

Written every which way

Won the lottery - how do I keep the money?



Having problems with creating a new field in a shape file



The Next CEO of Stack OverflowWhere clause problems when all parts are user input variablesDetermining Shape Area Field NameTrying to preserve attributes using SearchCursorTransferring one field name from text file to new field name in feature class?Problems with insert cursorHow to reorder field in a file geodatabase without creating a new feature class?Add new field with the name based on another fieldArcPy Cursor does not fill new field?Having problems returning the Total Sum of my Value FieldUpdate field of attribute table of a shape in selected rows with arcpy












0















I am new to scripting and to Python/arcpy. My intention with this script is to:




  • select points from a featureclass that fall within a target polygon and that meet an attribute query specified by the 'amenities' variable.

  • create three new featureclasses of these points.

  • add a new textfield to each of the featureclasses.

  • update that field.


I am stuck at the step where I would add the new field to each new feature class and update the cursor.



This is my first time posting on a message board, so I apologize if I have anything in the wrong format. Any advice would be helpful.



#Determine area of interst and make seperate shape files of amenities of interest
import arcpy
import os

arcpy.env.overwriteOutput = True

#Ammenities of interest
amenities = ['school', 'hospital', 'place of worship']
#Country of interest
targetCountry = 'El Salvador'
#Source of Data
dataSource = "Open Source"
#Central America shape file that is needed to find EL Salvador
countries = "C:\GEOG485\Lesson3\Lesson3Data\CentralAmerica.shp"
#All amenities are located here
points = "C:\GEOG485\Lesson3\Lesson3Data\OSMpoints.shp"
#Output folder
targetPoints = "C:\GEOG485\Lesson3\Lesson3Data\Output"

arcpy.env.workspace = "C:\GEOG485\Lesson3"
#Isolate the country polygon of interest
try:
countryQuery = '"NAME" = ' + "'" + targetCountry + "'"
print countryQuery

arcpy.MakeFeatureLayer_management(countries, "targetCountryLayer", countryQuery)
print arcpy.Exists("targetCountryLayer")

except:
print ("Error, try again")

try:
for amenity in amenities:
amenitySelectionClause = '"amenity" = ' + "'" + amenity + "'"
#Make a feature layer for the amenities of interest
arcpy.MakeFeatureLayer_management(points, "pointLayer", amenitySelectionClause)
#Narrow the amenities of interest to just inside the selected country
arcpy.SelectLayerByLocation_management("pointLayer", "CONTAINED_BY", "targetCountryLayer")
#Seperate shape file for each point of interest
targetShp = os.path.join(targetPoints, "{}.shp".format(amenity))
arcpy.CopyFeatures_management("pointLayer", targetShp)
#Verify the field name that will be added to the attribute table and string size
fieldName = arcpy.ValidateFieldName("Source")
arcpy.AddField_management(targetShp, fieldName, "Text", "", "", 25)
#Add row and enter text of where the data came from
with arcpy.da.UpdateCursor(targetShp, fieldName) as cursor:
for row in cursor:
row = dataSource
cursor.updateRow(row)
print ("Sucess")

except:
print ("Error, try again")

arcpy.Delete_management("targetCountryLayer")
arcpy.Delete_management("pointLayer")
print ("cleanup")








share







New contributor




Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I am new to scripting and to Python/arcpy. My intention with this script is to:




    • select points from a featureclass that fall within a target polygon and that meet an attribute query specified by the 'amenities' variable.

    • create three new featureclasses of these points.

    • add a new textfield to each of the featureclasses.

    • update that field.


    I am stuck at the step where I would add the new field to each new feature class and update the cursor.



    This is my first time posting on a message board, so I apologize if I have anything in the wrong format. Any advice would be helpful.



    #Determine area of interst and make seperate shape files of amenities of interest
    import arcpy
    import os

    arcpy.env.overwriteOutput = True

    #Ammenities of interest
    amenities = ['school', 'hospital', 'place of worship']
    #Country of interest
    targetCountry = 'El Salvador'
    #Source of Data
    dataSource = "Open Source"
    #Central America shape file that is needed to find EL Salvador
    countries = "C:\GEOG485\Lesson3\Lesson3Data\CentralAmerica.shp"
    #All amenities are located here
    points = "C:\GEOG485\Lesson3\Lesson3Data\OSMpoints.shp"
    #Output folder
    targetPoints = "C:\GEOG485\Lesson3\Lesson3Data\Output"

    arcpy.env.workspace = "C:\GEOG485\Lesson3"
    #Isolate the country polygon of interest
    try:
    countryQuery = '"NAME" = ' + "'" + targetCountry + "'"
    print countryQuery

    arcpy.MakeFeatureLayer_management(countries, "targetCountryLayer", countryQuery)
    print arcpy.Exists("targetCountryLayer")

    except:
    print ("Error, try again")

    try:
    for amenity in amenities:
    amenitySelectionClause = '"amenity" = ' + "'" + amenity + "'"
    #Make a feature layer for the amenities of interest
    arcpy.MakeFeatureLayer_management(points, "pointLayer", amenitySelectionClause)
    #Narrow the amenities of interest to just inside the selected country
    arcpy.SelectLayerByLocation_management("pointLayer", "CONTAINED_BY", "targetCountryLayer")
    #Seperate shape file for each point of interest
    targetShp = os.path.join(targetPoints, "{}.shp".format(amenity))
    arcpy.CopyFeatures_management("pointLayer", targetShp)
    #Verify the field name that will be added to the attribute table and string size
    fieldName = arcpy.ValidateFieldName("Source")
    arcpy.AddField_management(targetShp, fieldName, "Text", "", "", 25)
    #Add row and enter text of where the data came from
    with arcpy.da.UpdateCursor(targetShp, fieldName) as cursor:
    for row in cursor:
    row = dataSource
    cursor.updateRow(row)
    print ("Sucess")

    except:
    print ("Error, try again")

    arcpy.Delete_management("targetCountryLayer")
    arcpy.Delete_management("pointLayer")
    print ("cleanup")








    share







    New contributor




    Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I am new to scripting and to Python/arcpy. My intention with this script is to:




      • select points from a featureclass that fall within a target polygon and that meet an attribute query specified by the 'amenities' variable.

      • create three new featureclasses of these points.

      • add a new textfield to each of the featureclasses.

      • update that field.


      I am stuck at the step where I would add the new field to each new feature class and update the cursor.



      This is my first time posting on a message board, so I apologize if I have anything in the wrong format. Any advice would be helpful.



      #Determine area of interst and make seperate shape files of amenities of interest
      import arcpy
      import os

      arcpy.env.overwriteOutput = True

      #Ammenities of interest
      amenities = ['school', 'hospital', 'place of worship']
      #Country of interest
      targetCountry = 'El Salvador'
      #Source of Data
      dataSource = "Open Source"
      #Central America shape file that is needed to find EL Salvador
      countries = "C:\GEOG485\Lesson3\Lesson3Data\CentralAmerica.shp"
      #All amenities are located here
      points = "C:\GEOG485\Lesson3\Lesson3Data\OSMpoints.shp"
      #Output folder
      targetPoints = "C:\GEOG485\Lesson3\Lesson3Data\Output"

      arcpy.env.workspace = "C:\GEOG485\Lesson3"
      #Isolate the country polygon of interest
      try:
      countryQuery = '"NAME" = ' + "'" + targetCountry + "'"
      print countryQuery

      arcpy.MakeFeatureLayer_management(countries, "targetCountryLayer", countryQuery)
      print arcpy.Exists("targetCountryLayer")

      except:
      print ("Error, try again")

      try:
      for amenity in amenities:
      amenitySelectionClause = '"amenity" = ' + "'" + amenity + "'"
      #Make a feature layer for the amenities of interest
      arcpy.MakeFeatureLayer_management(points, "pointLayer", amenitySelectionClause)
      #Narrow the amenities of interest to just inside the selected country
      arcpy.SelectLayerByLocation_management("pointLayer", "CONTAINED_BY", "targetCountryLayer")
      #Seperate shape file for each point of interest
      targetShp = os.path.join(targetPoints, "{}.shp".format(amenity))
      arcpy.CopyFeatures_management("pointLayer", targetShp)
      #Verify the field name that will be added to the attribute table and string size
      fieldName = arcpy.ValidateFieldName("Source")
      arcpy.AddField_management(targetShp, fieldName, "Text", "", "", 25)
      #Add row and enter text of where the data came from
      with arcpy.da.UpdateCursor(targetShp, fieldName) as cursor:
      for row in cursor:
      row = dataSource
      cursor.updateRow(row)
      print ("Sucess")

      except:
      print ("Error, try again")

      arcpy.Delete_management("targetCountryLayer")
      arcpy.Delete_management("pointLayer")
      print ("cleanup")








      share







      New contributor




      Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I am new to scripting and to Python/arcpy. My intention with this script is to:




      • select points from a featureclass that fall within a target polygon and that meet an attribute query specified by the 'amenities' variable.

      • create three new featureclasses of these points.

      • add a new textfield to each of the featureclasses.

      • update that field.


      I am stuck at the step where I would add the new field to each new feature class and update the cursor.



      This is my first time posting on a message board, so I apologize if I have anything in the wrong format. Any advice would be helpful.



      #Determine area of interst and make seperate shape files of amenities of interest
      import arcpy
      import os

      arcpy.env.overwriteOutput = True

      #Ammenities of interest
      amenities = ['school', 'hospital', 'place of worship']
      #Country of interest
      targetCountry = 'El Salvador'
      #Source of Data
      dataSource = "Open Source"
      #Central America shape file that is needed to find EL Salvador
      countries = "C:\GEOG485\Lesson3\Lesson3Data\CentralAmerica.shp"
      #All amenities are located here
      points = "C:\GEOG485\Lesson3\Lesson3Data\OSMpoints.shp"
      #Output folder
      targetPoints = "C:\GEOG485\Lesson3\Lesson3Data\Output"

      arcpy.env.workspace = "C:\GEOG485\Lesson3"
      #Isolate the country polygon of interest
      try:
      countryQuery = '"NAME" = ' + "'" + targetCountry + "'"
      print countryQuery

      arcpy.MakeFeatureLayer_management(countries, "targetCountryLayer", countryQuery)
      print arcpy.Exists("targetCountryLayer")

      except:
      print ("Error, try again")

      try:
      for amenity in amenities:
      amenitySelectionClause = '"amenity" = ' + "'" + amenity + "'"
      #Make a feature layer for the amenities of interest
      arcpy.MakeFeatureLayer_management(points, "pointLayer", amenitySelectionClause)
      #Narrow the amenities of interest to just inside the selected country
      arcpy.SelectLayerByLocation_management("pointLayer", "CONTAINED_BY", "targetCountryLayer")
      #Seperate shape file for each point of interest
      targetShp = os.path.join(targetPoints, "{}.shp".format(amenity))
      arcpy.CopyFeatures_management("pointLayer", targetShp)
      #Verify the field name that will be added to the attribute table and string size
      fieldName = arcpy.ValidateFieldName("Source")
      arcpy.AddField_management(targetShp, fieldName, "Text", "", "", 25)
      #Add row and enter text of where the data came from
      with arcpy.da.UpdateCursor(targetShp, fieldName) as cursor:
      for row in cursor:
      row = dataSource
      cursor.updateRow(row)
      print ("Sucess")

      except:
      print ("Error, try again")

      arcpy.Delete_management("targetCountryLayer")
      arcpy.Delete_management("pointLayer")
      print ("cleanup")






      arcpy fields-attributes cursor





      share







      New contributor




      Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 5 mins ago









      WillWill

      1




      1




      New contributor




      Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes












          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
          });


          }
          });






          Will is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317210%2fhaving-problems-with-creating-a-new-field-in-a-shape-file%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Will is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Will is a new contributor. Be nice, and check out our Code of Conduct.













          Will is a new contributor. Be nice, and check out our Code of Conduct.












          Will 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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317210%2fhaving-problems-with-creating-a-new-field-in-a-shape-file%23new-answer', 'question_page');
          }
          );

          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







          Popular posts from this blog

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

          Meter-Bus Содержание Параметры шины | Стандартизация |...