POST
|
When using Web AppBuilder to design Web Maps, you can use a Feature Service or a Map Service URL as the embedded map within the application, which is best practices and what are the pros and cons for each? Thank you
... View more
07-14-2020
04:00 PM
|
0
|
2
|
810
|
POST
|
Robert, I figured out how to build the object the applyEdits() graphics needed and that worked. I am not familiar with Query Task I will read up on it. thank you.
... View more
01-30-2020
12:51 PM
|
0
|
0
|
1002
|
POST
|
I want to use a relationship class GDB object to relate multiple (i.e. two) non-spatial tables (say table name 'Historical Records' and table name 'Recommendations') to my feature layer. My concern is that if someone deletes a polygon and redraws it on a sde two-way replication connection for that feature layer, new objectIDs will be created on that feature layer and thereby breaking my connections between the non-spatial tables and my feature layer. Does ESRI have a way of handling this?
... View more
01-30-2020
12:48 PM
|
0
|
2
|
479
|
BLOG
|
Suzanne, I want to use a realtional Class GDB object to relate multiple tables to my feature layer. My concern is that if someone deletes a polygon and redraws it on a sde two-way replication connection, that new objectIDs will be created for the feature layer and thereby breaking my connections between the non-spatial tables and my feature layer. Do you know if esri has a way of handling this?
... View more
01-30-2020
12:43 PM
|
0
|
0
|
7084
|
POST
|
Ken Buja, I don't think it is needed. I have since taken it out. My response is given in the correct spatial reference. I do not know if I need to declare it within the object I am putting in as the geometry object into applyEdits(); my problem is I am unable to find out, so far, exactly what parameters and what sort of object applyEdits() needs to add a geometry. I do know that sketchViewModel.on("draw-complete", function(evt) { geometryForSketch = evt.geometry; }); gives me the correct object, while my geometryObj = response.data.features[0].geometry.rings[0]; or geometryObj = response.data.features[0].geometry.rings; geometryObj = response.data.features[0].geometry; does not give me what I need.
... View more
01-28-2020
10:37 AM
|
0
|
1
|
1330
|
POST
|
Version:1.0 StartHTML:000000286 EndHTML:000017318 StartFragment:000002743 EndFragment:000017286 StartSelection:000002743 EndSelection:000017286 SourceURL:https://community.esri.com/discussion/create.jspa?suppressMarkQuestion=true&question=true&containerType=14&containerID=2128 I want to use a geometry object from an esriRequest to add a graphic to a featureLayer. I present the client with two options: 1.) use the SketchViewModel draw tool to create a polygon to add a new graphic to the featureLayer, and 2.) use a dropdown box selector to choose a specific Field Office boundary polygon to add a new graphic to the featureLayer. While the draw tool works fine, when I obtain my geometry object from the esriRequest it will not display when I later go to that record and attempt to display the geometry on my web map. <script> var geometryFromSketch; var geometryObj; require([ "esri/Map", "esri/views/MapView", "esri/widgets/Sketch/SketchViewModel", "esri/Graphic", "esri/layers/GraphicsLayer", "esri/layers/GeoRSSLayer", "esri/layers/FeatureLayer", "esri/layers/MapImageLayer", "esri/geometry/SpatialReference", "esri/geometry/Polygon", "dojo/domReady!" ], function(Map, MapView, SketchViewModel, Graphic, GraphicsLayer, GeoRSSLayer, FeatureLayer, MapImageLayer, Polygon) { // GraphicsLayer to hold graphics created via sketch view model var tempGraphicsLayer = new GraphicsLayer(); const featureLayer = new FeatureLayer({ url: "https://gis.nm.blm.doi.net/arcgis/rest/services/Stipulations/BLM_NM_OG_Stips_Poly/FeatureServer/0/addFeatures" }); // Point to the rss feed url var layer = new MapImageLayer({ url: "https://gis.blm.gov/nmarcgis/rest/services/Base/BLM_NM_Reference_Boundaries/MapServer" }); var map = new Map({ basemap: "national-geographic", layers: [layer, tempGraphicsLayer] }); var view = new MapView({ container: "viewDiv", map: map, zoom: 6, center: [-106.1499021874988, 34.44280009376313] }); view.when(function() { // create a new sketch view model var sketchViewModel = new SketchViewModel({ view: view, layer: tempGraphicsLayer, pointSymbol: { // symbol used for points type: "simple-marker", // autocasts as new SimpleMarkerSymbol() style: "circle", color: "#72ACCB", size: "16px", outline: { // autocasts as new SimpleLineSymbol() color: [255, 255, 255], width: 3 // points } }, polylineSymbol: { // symbol used for polylines type: "simple-line", // autocasts as new SimpleMarkerSymbol() color: "#72ACCB", width: "4", style: "dash" }, polygonSymbol: { // symbol used for polygons type: "simple-fill", // autocasts as new SimpleMarkerSymbol() color: "rgba(114,172,203, 0.7)", style: "solid", outline: { color: "white", width: 1 } } }); // ************************************************************ // Get the completed graphic from the event and add it to view. // This event fires when user presses // * "C" key to finish sketching point, polygon or polyline. // * Double-clicks to finish sketching polyline or polygon. // * Clicks to finish sketching a point geometry. // *********************************************************** sketchViewModel.on("draw-complete", function(evt) { //console.log("evtGeo", evt.geometry) ; geometryForSketch = evt.geometry; document.getElementById('GISGeometry').value = 'Geometry Input'; // add the graphic to the graphics layer tempGraphicsLayer.add(evt.graphic); setActiveButton(); }); // Call FeatureLayer.applyEdits() with specified params. function applyEditsToIncidents(params) { // unselectFeature(); featureLayer .applyEdits(params) .then(function(){ unloadLoadingGif(); window.location.href = "http://it4rmdev.blm.doi.net/Michaels_Leasing_Stipulations_Proof_11_25_2019/StipPages/stipulationsList.cfm"; }) .catch(function(error) { unloadLoadingGif(); console.log("==============================================="); console.error( "[ applyEdits ] FAILURE: ", error.code, error.name, error.message ); console.log("error = ", error); }); } // ************************************* // activate the sketch to create a point // ************************************* var submitButton = document.getElementById("submitButton"); submitButton.onclick = function() { <!---GET SELECTED VALUE OF FIELD OFFICE DROPDOWN---> var fOSelectVal = document.getElementById('fieldOfficeShp').options[ document.getElementById('fieldOfficeShp').selectedIndex ].value; <!---GET SELECTED VALUE OF FIELD OFFICE DROPDOWN---> loadLoadingGif('/Settings/Images/Loading.gif'); if(fOSelectVal == ' ' ) { geometryObj = geometryForSketch; console.log("geo", geometryObj); } else { <!---POPULATE ESRI AJAX WHERE CLAUSE BASED ON FIELD OFFICE DROPDOWN SELECTION---> if(fOSelectVal == "Las Cruces District Office"){ var Clause = "ADMU_NAME = 'LAS CRUCES DISTRICT OFFICE'" } else if(fOSelectVal == "Carlsbad Field Office"){ var Clause = "ADMU_NAME = 'CARLSBAD FIELD OFFICE'" } else if(fOSelectVal == "Socorro Field Office"){ var Clause = "ADMU_NAME = 'SOCORRO FIELD OFFICE'" } else if(fOSelectVal == "Roswell Field Office"){ var Clause = "ADMU_NAME = 'ROSWELL FIELD OFFICE'" } else if(fOSelectVal == "Rio Puerco Field Office"){ var Clause = "ADMU_NAME = 'RIO PUERCO FIELD OFFICE'" } else if(fOSelectVal == "Taos Field Office"){ var Clause = "ADMU_NAME = 'TAOS FIELD OFFICE'" } else if(fOSelectVal == "Farmington Field Office"){ var Clause = "ADMU_NAME = 'FARMINGTON FIELD OFFICE'" } else if(fOSelectVal == "Oklahoma Field Office"){ var Clause = "ADMU_NAME = 'OKLAHOMA FIELD OFFICE'" } <!---POPULATE ESRI AJAX WHERE CLAUSE BASED ON FIELD OFFICE DROPDOWN SELECTION---> <!---ESRI FUNCTION FOR INTERSECTING GEOMETERIES AND PERFORMING ALL AJAX CALLS BASED ON QUERY SELECTIONS---> require(["esri/request"], function(esriRequest) { /************************************************ * * Define the 'options' for our request. * *************************************************/ <!---VARIABLES FOR PROJECT GEOMETRY GET---> var options = { // These properties will be appended to the request URL in the following format: // <url>?f=json query: { f: "json", geometryType: "esriGeometryPolygon", where: Clause, geometryPrecision: 3, outSR: 3857 }, // Determine the format you want to read the response as. // Default type is 'json'. Other values are 'xml', 'text', 'blob', 'arraybuffer', 'document'. responseType: "json" }; <!---VARIABLES FOR PROJECT GEOMETRY GET---> <!---SET URL VARIABLE FOR JSON CALL TO ESRI PROJECT_POLY DB---> var url = "https://gis.blm.gov/nmarcgis/rest/services/Base/BLM_NM_Reference_Boundaries/MapServer/0/query"; <!---SET URL VARIABLE FOR JSON CALL TO ESRI PROJECT_POLY DB---> <!---ESRI AJAX REQUEST TO GET FIELD OFFICE BOUNDARY GEOMETRY---> esriRequest(url, options).then( function(response) { unloadLoadingGif(); geometryObj= response.data.features[0].geometry.rings; document.getElementById('GISGeometry').value = 'Geometry Input'; <!---console.log("geo2", response.data.features[0].geometry);---> console.log("geo3", geometryObj); }); }); } var Res = document.getElementById('optResource'); var Stat = document.getElementById('optStatus'); var Type = document.getElementById('optType'); var AdmFldOff = document.getElementById('optFO'); var RMPA = document.getElementById('optRMPA'); var Dsgntn = document.getElementById('optDsgntn'); var ROD_Yr = document.getElementById('optROD_Yr'); var State = document.getElementById('optState'); var AdmState = document.getElementById('optAdminState'); var DataSrc = document.getElementById('optDataSrc'); //build geometry object to add var polygon = Polygon({ f: json, type: "polygon", // autocasts as new Polygon() rings: geometryObj, spatialReference: {"latestWkid":3857,"wkid":102100 } }); editFeature = new Graphic({ geometry: polygon, attributes: { OG_STIP_ID: document.getElementById('txtStipID').value, OG_STIP_NA: document.getElementById('txtTitle').value, OG_STIP_TYPE: Type.options[Type.selectedIndex].value, OG_STIP_CNTNT: document.getElementById('txtDescript').value, PRPSE: document.getElementById('txtPurpose').value, PRCDNG_RMP_RMPA: RMPA.options[RMPA.selectedIndex].value, AFFCTED_RESRCE: Res.options[Res.selectedIndex].value, STATUS: Stat.options[Stat.selectedIndex].value, DSGNTN: Dsgntn.options[Dsgntn.selectedIndex].value, GEO_STATE: State.options[State.selectedIndex].value, ADMIN_ST: AdmState.options[AdmState.selectedIndex].value, ADM_UNIT_CD: AdmFldOff.options[AdmFldOff.selectedIndex].value, ROD_YR: ROD_Yr.options[ROD_Yr.selectedIndex].value, SITE_NA: document.getElementById('txtSite').value, DATA_SRCE: DataSrc.options[DataSrc.selectedIndex].value, GEN_COMMENTS: document.getElementById('txtGenComm').value, WAIVER: document.getElementById('txtWaiver').value, EXCPTN: document.getElementById('txtException').value, MODFCTN: document.getElementById('txtModif').value <!---USER_ID: <cfoutput>'#Session.getAuthUser#'</cfoutput>,---> <!---DATE_CREATED: "2019-11-05 00:00:00.0",---> } }); const edits = { addFeatures: [editFeature] }; applyEditsToIncidents(edits); }; <!---END OF SUBMIT BUTTON CLICK ()---> // *************************************** // activate the sketch to create a polygon // *************************************** var drawPolygonButton = document.getElementById("polygonButton"); drawPolygonButton.onclick = function() { // set the sketch to create a polygon geometry tempGraphicsLayer.removeAll(); sketchViewModel.reset(); document.getElementById('GISGeometry').value = ''; sketchViewModel.create("polygon"); setActiveButton(this); }; // ************** // reset button // ************** document.getElementById("resetBtn").onclick = function() { tempGraphicsLayer.removeAll(); sketchViewModel.reset(); document.getElementById('GISGeometry').value = ''; setActiveButton(); }; function setActiveButton(selectedButton) { // focus the view to activate keyboard shortcuts for sketching view.focus(); var elements = document.getElementsByClassName("active"); for (var i = 0; i < elements.length; i++) { elements.classList.remove("active"); } if (selectedButton) { selectedButton.classList.add("active"); } }; }); }); </script>
... View more
01-28-2020
09:58 AM
|
0
|
2
|
1375
|
POST
|
I want to use a geometry object from an esriRequest to add a graphic to a featureLayer. I present the client with two options: 1.) use the SketchViewModel draw tool to create a polygon to add a new graphic to the featureLayer, and 2.) use a dropdown box selector to choose a specific Field Office boundary polygon to add a new graphic to the featureLayer. While the draw tool works fine, when I obtain my geometry object from the esriRequest it will not display when I later go to that record and attempt to display the geometry on my web map. <script> var geometryFromSketch; var geometryObj; require([ "esri/Map", "esri/views/MapView", "esri/widgets/Sketch/SketchViewModel", "esri/Graphic", "esri/layers/GraphicsLayer", "esri/layers/GeoRSSLayer", "esri/layers/FeatureLayer", "esri/layers/MapImageLayer", "esri/geometry/SpatialReference", "esri/geometry/Polygon", "dojo/domReady!" ], function(Map, MapView, SketchViewModel, Graphic, GraphicsLayer, GeoRSSLayer, FeatureLayer, MapImageLayer, Polygon) { // GraphicsLayer to hold graphics created via sketch view model var tempGraphicsLayer = new GraphicsLayer(); const featureLayer = new FeatureLayer({ url: "https://gis.nm.blm.doi.net/arcgis/rest/services/Stipulations/BLM_NM_OG_Stips_Poly/FeatureServer/0/addFeatures" }); // Point to the rss feed url var layer = new MapImageLayer({ url: "https://gis.blm.gov/nmarcgis/rest/services/Base/BLM_NM_Reference_Boundaries/MapServer" }); var map = new Map({ basemap: "national-geographic", layers: [layer, tempGraphicsLayer] }); var view = new MapView({ container: "viewDiv", map: map, zoom: 6, center: [-106.1499021874988, 34.44280009376313] }); view.when(function() { // create a new sketch view model var sketchViewModel = new SketchViewModel({ view: view, layer: tempGraphicsLayer, pointSymbol: { // symbol used for points type: "simple-marker", // autocasts as new SimpleMarkerSymbol() style: "circle", color: "#72ACCB", size: "16px", outline: { // autocasts as new SimpleLineSymbol() color: [255, 255, 255], width: 3 // points } }, polylineSymbol: { // symbol used for polylines type: "simple-line", // autocasts as new SimpleMarkerSymbol() color: "#72ACCB", width: "4", style: "dash" }, polygonSymbol: { // symbol used for polygons type: "simple-fill", // autocasts as new SimpleMarkerSymbol() color: "rgba(114,172,203, 0.7)", style: "solid", outline: { color: "white", width: 1 } } }); // ************************************************************ // Get the completed graphic from the event and add it to view. // This event fires when user presses // * "C" key to finish sketching point, polygon or polyline. // * Double-clicks to finish sketching polyline or polygon. // * Clicks to finish sketching a point geometry. // *********************************************************** sketchViewModel.on("draw-complete", function(evt) { //console.log("evtGeo", evt.geometry) ; geometryForSketch = evt.geometry; document.getElementById('GISGeometry').value = 'Geometry Input'; // add the graphic to the graphics layer tempGraphicsLayer.add(evt.graphic); setActiveButton(); }); // Call FeatureLayer.applyEdits() with specified params. function applyEditsToIncidents(params) { // unselectFeature(); featureLayer .applyEdits(params) .then(function(){ unloadLoadingGif(); window.location.href = "http://it4rmdev.blm.doi.net/Michaels_Leasing_Stipulations_Proof_11_25_2019/StipPages/stipulationsList.cfm"; }) .catch(function(error) { unloadLoadingGif(); console.log("==============================================="); console.error( "[ applyEdits ] FAILURE: ", error.code, error.name, error.message ); console.log("error = ", error); }); } // ************************************* // activate the sketch to create a point // ************************************* var submitButton = document.getElementById("submitButton"); submitButton.onclick = function() { <!---GET SELECTED VALUE OF FIELD OFFICE DROPDOWN---> var fOSelectVal = document.getElementById('fieldOfficeShp').options[ document.getElementById('fieldOfficeShp').selectedIndex ].value; <!---GET SELECTED VALUE OF FIELD OFFICE DROPDOWN---> loadLoadingGif('/Settings/Images/Loading.gif'); if(fOSelectVal == ' ' ) { geometryObj = geometryForSketch; console.log("geo", geometryObj); } else { <!---POPULATE ESRI AJAX WHERE CLAUSE BASED ON FIELD OFFICE DROPDOWN SELECTION---> if(fOSelectVal == "Las Cruces District Office"){ var Clause = "ADMU_NAME = 'LAS CRUCES DISTRICT OFFICE'" } else if(fOSelectVal == "Carlsbad Field Office"){ var Clause = "ADMU_NAME = 'CARLSBAD FIELD OFFICE'" } else if(fOSelectVal == "Socorro Field Office"){ var Clause = "ADMU_NAME = 'SOCORRO FIELD OFFICE'" } else if(fOSelectVal == "Roswell Field Office"){ var Clause = "ADMU_NAME = 'ROSWELL FIELD OFFICE'" } else if(fOSelectVal == "Rio Puerco Field Office"){ var Clause = "ADMU_NAME = 'RIO PUERCO FIELD OFFICE'" } else if(fOSelectVal == "Taos Field Office"){ var Clause = "ADMU_NAME = 'TAOS FIELD OFFICE'" } else if(fOSelectVal == "Farmington Field Office"){ var Clause = "ADMU_NAME = 'FARMINGTON FIELD OFFICE'" } else if(fOSelectVal == "Oklahoma Field Office"){ var Clause = "ADMU_NAME = 'OKLAHOMA FIELD OFFICE'" } <!---POPULATE ESRI AJAX WHERE CLAUSE BASED ON FIELD OFFICE DROPDOWN SELECTION---> <!---ESRI FUNCTION FOR INTERSECTING GEOMETERIES AND PERFORMING ALL AJAX CALLS BASED ON QUERY SELECTIONS---> require(["esri/request"], function(esriRequest) { /************************************************ * * Define the 'options' for our request. * *************************************************/ <!---VARIABLES FOR PROJECT GEOMETRY GET---> var options = { // These properties will be appended to the request URL in the following format: // <url>?f=json query: { f: "json", geometryType: "esriGeometryPolygon", where: Clause, geometryPrecision: 3, outSR: 3857 }, // Determine the format you want to read the response as. // Default type is 'json'. Other values are 'xml', 'text', 'blob', 'arraybuffer', 'document'. responseType: "json" }; <!---VARIABLES FOR PROJECT GEOMETRY GET---> <!---SET URL VARIABLE FOR JSON CALL TO ESRI PROJECT_POLY DB---> var url = "https://gis.blm.gov/nmarcgis/rest/services/Base/BLM_NM_Reference_Boundaries/MapServer/0/query"; <!---SET URL VARIABLE FOR JSON CALL TO ESRI PROJECT_POLY DB---> <!---ESRI AJAX REQUEST TO GET FIELD OFFICE BOUNDARY GEOMETRY---> esriRequest(url, options).then( function(response) { unloadLoadingGif(); geometryObj= response.data.features[0].geometry.rings; document.getElementById('GISGeometry').value = 'Geometry Input'; <!---console.log("geo2", response.data.features[0].geometry);---> console.log("geo3", geometryObj); }); }); } var Res = document.getElementById('optResource'); var Stat = document.getElementById('optStatus'); var Type = document.getElementById('optType'); var AdmFldOff = document.getElementById('optFO'); var RMPA = document.getElementById('optRMPA'); var Dsgntn = document.getElementById('optDsgntn'); var ROD_Yr = document.getElementById('optROD_Yr'); var State = document.getElementById('optState'); var AdmState = document.getElementById('optAdminState'); var DataSrc = document.getElementById('optDataSrc'); //build geometry object to add var polygon = Polygon({ f: json, type: "polygon", // autocasts as new Polygon() rings: geometryObj, spatialReference: {"latestWkid":3857,"wkid":102100 } }); editFeature = new Graphic({ geometry: polygon, attributes: { OG_STIP_ID: document.getElementById('txtStipID').value, OG_STIP_NA: document.getElementById('txtTitle').value, OG_STIP_TYPE: Type.options[Type.selectedIndex].value, OG_STIP_CNTNT: document.getElementById('txtDescript').value, PRPSE: document.getElementById('txtPurpose').value, PRCDNG_RMP_RMPA: RMPA.options[RMPA.selectedIndex].value, AFFCTED_RESRCE: Res.options[Res.selectedIndex].value, STATUS: Stat.options[Stat.selectedIndex].value, DSGNTN: Dsgntn.options[Dsgntn.selectedIndex].value, GEO_STATE: State.options[State.selectedIndex].value, ADMIN_ST: AdmState.options[AdmState.selectedIndex].value, ADM_UNIT_CD: AdmFldOff.options[AdmFldOff.selectedIndex].value, ROD_YR: ROD_Yr.options[ROD_Yr.selectedIndex].value, SITE_NA: document.getElementById('txtSite').value, DATA_SRCE: DataSrc.options[DataSrc.selectedIndex].value, GEN_COMMENTS: document.getElementById('txtGenComm').value, WAIVER: document.getElementById('txtWaiver').value, EXCPTN: document.getElementById('txtException').value, MODFCTN: document.getElementById('txtModif').value <!---USER_ID: <cfoutput>'#Session.getAuthUser#'</cfoutput>,---> <!---DATE_CREATED: "2019-11-05 00:00:00.0",---> } }); const edits = { addFeatures: [editFeature] }; applyEditsToIncidents(edits); }; <!---END OF SUBMIT BUTTON CLICK ()---> // *************************************** // activate the sketch to create a polygon // *************************************** var drawPolygonButton = document.getElementById("polygonButton"); drawPolygonButton.onclick = function() { // set the sketch to create a polygon geometry tempGraphicsLayer.removeAll(); sketchViewModel.reset(); document.getElementById('GISGeometry').value = ''; sketchViewModel.create("polygon"); setActiveButton(this); }; // ************** // reset button // ************** document.getElementById("resetBtn").onclick = function() { tempGraphicsLayer.removeAll(); sketchViewModel.reset(); document.getElementById('GISGeometry').value = ''; setActiveButton(); }; function setActiveButton(selectedButton) { // focus the view to activate keyboard shortcuts for sketching view.focus(); var elements = document.getElementsByClassName("active"); for (var i = 0; i < elements.length; i++) { elements.classList.remove("active"); } if (selectedButton) { selectedButton.classList.add("active"); } }; }); }); </script>
... View more
01-28-2020
09:57 AM
|
1
|
4
|
1408
|
POST
|
I am attempting to create a csv file containing field_names as headers on the first row and input attributes under those field_Names column wise. First, I iterate through a list of data_sets: then i iterate through a list of feature_classes, search for specific field_names, and return the field_name value first found to match. I end up with a large list [] containing about 40 dicts{} and these dicts{} in turn contain each one a key and a list[] as the value pair: that list being the attributes found under the header(i.e.Field_Name that matched). I also have a function that transposes the data to be input column wise regardless of the attr. data list size, but for some reason I am getting an error: ValueError:dict contains fields not in fieldnames: Which is from the csv.DictWriter() function, but I have specified the fieldnames = headers in the function. In regards to the error it is looking at the first item in each attr. list[] conatined in each dict{}, but why is it looking for 'fieldnames' there? these are the values not the keys. Please help #function to transpose data col-wise
def transposeANDwriteCSV(csvwriter, data) :
maxLength = 0 # init maxLength to zero
for item in data : # loop through the data list
myKeysView = item.keys() # find the single key in each item (IS IT POSSIBLE THAT A KEY DOESN'T EXIST - MAY NEED TO CHECK)
myKeys = list(myKeysView)
myList = item.get(myKeys[0]) # retrieve the list in each item (IS IT POSSIBLE THAT A LIST FOR THIS KEY DOESN'T EXIST )
if (len(myList) > maxLength) : # Check if the length of this list is the longest one.
maxLength = len(myList) # If it is the longest then save.
# then loop through the main data list maxLength number of times
for i in range (0,maxLength) : #loop through the entire data list until you have retrieved all the data
myRow = [] #create a row list tthat you will build each pass through the loop
for item in data :
myKeysView = item.keys() # find the single key in this item
myKeys = list(myKeysView)
myList = item.get(myKeys[0]) # retrieve the list in this item
if(len(myList) >= (i + 1) ) : #check if this list still has data remaining to retrieve
myRow.append(myList[i]) # if it still has data then retrieve it and put into the row.
else :
myRow.append("") # if no data remains in this list then fill next cell in row with blank.
csvwriter.writerow(myRow) # write row each time through maxLength loop
#function to find a field_name match
def FindField(fc):
field_list = [
"NAME", "PROJECT_NAME", "LABEL", "Seed_Area", "SEED_MIX", "MINENAME", "ORIGINAL_L", "WETLAND_TYPE",
"PDF_NAME", "User_", "OwnerName", "Lessee", "Plot_Name", "Plant_comm", "PitName", "Quad",
"NOTES", "Range", "User", "ObjectID"
]
fields = [fld.name.upper() for fld in arcpy.ListFields(fc)] #returns all filenames for current fc
return next(f for f in field_list if f.upper() in fields)
##def createCSV(data, csvname, mode ='ab'):
## with open(csvname, mode) as csvfile:
## csvwriter = csv.writer(csvfile, delimiter="'")
## csvwriter.writerow([data])
import arcpy
import csv
import os
csvname = r"U:\My Documents\ArcGIS\ArcPyOutputFiles\class1(type1)PolyAttrsss.csv"
arcpy.env.workspace = r"V:\tools\ArcSDE\Database Connections\5 NMSO ilmnmso3gi1 ilmnmsoclass1 (Type 1) Default.sde"
datasets = arcpy.ListDatasets("*FFO*", "Feature")
datasets = [''] + datasets if datasets is not None else []
headers = []
data=[]
#iterate through a list of datasets, then through a list of feature_classes
for ds in datasets:
for fc in arcpy.ListFeatureClasses("*FFO*", "Polygon", feature_dataset=ds):
path = os.path.join( ds, fc)
headers.append(path)
dataDict = {}
colData = []
FldName = FindField(fc)
## createCSV(FldName, csvname)
colData.append(FldName)
with arcpy.da.SearchCursor(fc, [FldName]) as sc:
for row in sc:
name = row[0]
colData.append(name)
## createCSV(name, csvname)
dataDict[path] = colData
data.append(dataDict)
##print (data)
####print headers
##head = list(dataDict.keys())
##print head
##head = list(sorted(dataDict.keys()))
##print head
##
with open(csvname, mode = 'wb') as csvfile:
csvwriter = csv.DictWriter(csvfile, delimiter=",", fieldnames = headers)
csvwriter.writeheader()
transposeANDwriteCSV(csvwriter, data)
## csvwriter.writerows(zip(*data))
... View more
08-20-2019
12:39 PM
|
0
|
0
|
1558
|
POST
|
That is very cool, thanks. so the returned value in this case is the variable 'f' which contains the appropriate fieldName?
... View more
08-15-2019
01:48 PM
|
0
|
1
|
1609
|
POST
|
Correct. I am not concerned with the SDE path, only the EGDB and feature class path. My goal is to get a print out of all polygons contained in EGDB's with the text "FFO" in the title. Since there are multiple polygons within my feature classes I will need to get in there to print out the individual polys, but it is a bit tricky since there are not good data standards in place and therefore it is not obvious what fieldname contains attributes that will give me pertinent information. Otherwise it is days of digging through multiple EGDB's and feature classes.
... View more
08-15-2019
12:07 PM
|
0
|
0
|
388
|
POST
|
def FindField(fc)
if len(arcpy.ListFields(fc,"NAME"))>0:
FldName = "NAME"
Elif len(arcpy.ListFields(fc,"LABEL"))>0:
FldName = "LABEL"
Elif len(arcpy.ListFields(fc,"NOTES"))>0:
FldName = "NOTES"
Elif len(arcpy.ListFields(fc,"SEED_MIX"))>0:
FldName = "SEED_MIX"
Elif len(arcpy.ListFields(fc,"Range"))>0:
FldName = "Range"
Elif len(arcpy.ListFields(fc,"PROJECT_NAME"))>0:
FldName = "PROJECT_NAME"
Elif len(arcpy.ListFields(fc,"ORGINAL_L"))>0:
FldName = "ORGINAL_L"
Elif len(arcpy.ListFields(fc,"WETLAND_TYPE"))>0:
FldName = "WETLAND_TYPE"
Elif len(arcpy.ListFields(fc,"Dist_Type"))>0:
FldName = "Dist_Type"
Elif len(arcpy.ListFields(fc,"PROJECT_NAME"))>0:
FldName = "PROJECT_NAME"
Elif len(arcpy.ListFields(fc,"Lessee"))>0:
FldName = "Lessee"
Elif len(arcpy.ListFields(fc,"label"))>0:
FldName = "label"
Elif len(arcpy.ListFields(fc,"MINENAME"))>0:
FldName = "MINENAME"
Elif len(arcpy.ListFields(fc,"Project_Name"))>0:
FldName = "Project_Name"
Elif len(arcpy.ListFields(fc,"Plot_Name"))>0:
FldName = "Plot_Name"
Elif len(arcpy.ListFields(fc,"PitName"))>0:
FldName = "PitName"
Else Joshua, I believe this will answer the question as to what other possible fields exist. and this is not exclusive, but it will do as long as I code an option to ignore printing out anything other the feature class path containing field_names not listed.
... View more
08-15-2019
11:59 AM
|
0
|
3
|
1609
|
POST
|
Joshua, thanks for the response. Yes I do mean iterating through datasets, and then through feature classes, and then through individual polygons which are named in the attribute table in the feature classes. Thank you.
... View more
08-15-2019
09:23 AM
|
0
|
4
|
1609
|
POST
|
Thanks for the support here. The code below should work and it does to a point. I need a function that checks for various names the same way (if len(arcpy.ListFields(fc,"NAME"))>0:) checks for the Field_Name : 'NAME' and then assigns that to a variable(e.g FldName) to be used in the( with arcpy.da.SearchCursor(fc, ['FldName']) as sc:) call. I will need to only return the variable: 'path' if there is no appropriate Field_Name found. However, I cannot figure out why the csv function is throwing an error or putting individual letters in each cell on the row in the xl doc. def createCSV(data, csvname, mode ='ab'):
with open(csvname, mode) as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',')
csvwriter.writerow(data)
import arcpy
import csv
import os
csvname = r"U:\My Documents\ArcGIS\ArcPyOutputFiles\TestFile4.csv"
headers = 'Name', 'Path'
createCSV(headers, csvname, 'wb')
arcpy.env.workspace = r"V:\tools\ArcSDE\Database Connections\5 NMSO ilmnmso3gi1 ilmnmsoclass1 (Type 1) Default.sde"
datasets = arcpy.ListDatasets("*FFO*", "Feature")
datasets = [''] + datasets if datasets is not None else []
for ds in datasets:
for fc in arcpy.ListFeatureClasses("*FFO*", "Polygon", feature_dataset=ds):
path = os.path.join( ds, fc)
if len(arcpy.ListFields(fc,"NAME"))>0:
## print(path)
with arcpy.da.SearchCursor(fc, ['NAME']) as sc:
for row in sc:
data = row[0]
createCSV(data, csvname)
... View more
08-15-2019
09:21 AM
|
0
|
2
|
388
|
POST
|
I am attempting to write arcpy script that will iterate through an .sde connection database, finds all datasets containing polygons and the text "FFO" in the title, then selects for those and iterates through the feature_layers contained within. I can do this with : import arcpy import csv import os csvname = r"U:\My Documents\ArcGIS\ArcPyOutputFiles\TestFile4.csv" headers = 'Name', 'Path' createCSV(headers, csvname, 'wb') arcpy.env.workspace = r"V:\tools\ArcSDE\Database Connections\5 NMSO ilmnmso3gi1 ilmnmsoclass1 (Type 1) Default.sde" datasets = arcpy.ListDatasets("*FFO*", "Feature") datasets = [''] + datasets if datasets is not None else [] for ds in datasets: for fc in arcpy.ListFeatureClasses("*FFO*", "Polygon", feature_dataset=ds): path = os.path.join( ds, fc) #print(path). But there are multiple polygons in each feature layer, so I want to iterate through those as well. Which I can do with arcpy.da.SearchCursor() as long as the feature layers contain a similar field_name. But not all contain the word "NAME". So I thought this would work. arcpy.env.workspace = r"V:\tools\ArcSDE\Database Connections\5 NMSO ilmnmso3gi1 ilmnmsoclass1 (Type 1) Default.sde" datasets = arcpy.ListDatasets("*FFO*", "Feature") datasets = [''] + datasets if datasets is not None else [] for ds in datasets: for fc in arcpy.ListFeatureClasses("*FFO*", "Polygon", feature_dataset=ds): path = os.path.join( ds, fc) #print(path) desc = arcpy.Describe(fc) if hasattr(desc, 'name'): with arcpy.da.SearchCursor(fc, ['NAME']) as sc: for row in sc: Name = row[0] Path = row[1] data = Name, path createCSV(data, csvname) But it doesn't work. I want to load a csv file with a path to the data and an identifying name of each polygon contained in the feature layers, contained in the datasets. Thank you.
... View more
08-14-2019
04:04 PM
|
0
|
15
|
2237
|
Title | Kudos | Posted |
---|---|---|
1 | 01-28-2020 09:57 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|