POST
|
For future coders looking for "one" solution to this problem, I'm placing a short version of my final python solution. Thanks to Heidi Kristenson for help with setting the thumbnail in the xml. Problem: Update metadata on a geodatabase feature class from metadata maintained in a separate table. Include a thumbnail from an already created jpeg file. Solution: Export the metadata from the target feature class to a scratch XML file. Modify the xml file elements with the new metadata values as well as the thumbnail. Import the modified metadata back into the target geodatabase feature class. Of course, our solution iterates through a list of geodatabase feature classes to update the metadata which this sample does not illustrate for simplicity. import os
import arcpy
import xml.etree.ElementTree as ET
import base64
from pyodbc import connect as odbcconn
from pandas import read_sql_query as readsqlqry
num_elements = 0
featName = 'your_featureClassName'
fcPathName = 'Database Connections/your_geodatabase.sde/' + featName
# set up a connection to read user maintained metadata from a SQL Server table
metaConnStr = 'DRIVER={SQL Server};SERVER=servername;DATABASE=dbname;Trusted_Connection=yes'
conn = odbcconn(metaConnStr)
# your metadata source data will differ from the following
metaqry = 'SELECT [FULL_NAME],[COVER_NAME],[ABSTRACT],[UPDATEDATE],[OWNERNAME]' +\
',[PATH],[METAACCESS],[ONMAINT],[MAINTFREQ],[KNOWNERROR],[LINEAGE]' +\
',[DOMAIN],[RECTIFIED],[MAINTORG],[MAINTDESC],[LIBINPUT],[SOURCNAME]' +\
',[SOURCCONTACT],[SOURCDOCNAME],[SOURCDATE],[SOURCSCALE],[SOURCFORMAT]' +\
',[SOUR2NAME],[SOUR2CONTACT],[SOUR2DOCNAME],[SOUR2DATE],[SOUR2SCALE]' +\
',[SOUR2FORMAT],[ONMG],[MGLAYERNAME],[MGSCALELOW],[MGSCALEHIGH] ' +\
'FROM [dbo].[metadata] WHERE [COVER_NAME] = \'' + featName + '\''
df_FCMeta = readsqlqry(metaqry, conn) # load query result to pandas dataframe
df_row = df_FCMeta.iloc[0] # get the one row in the dataframe. There is only one row per COVER_NAME
arcpy.env.overwriteOutput = True
# export the ESRI generated metadata from the target feature class
# install location
dir = arcpy.GetInstallInfo('desktop')['InstallDir']
# stylesheet to use
copy_xslt = r'{0}'.format(os.path.join(dir,'Metadata\Stylesheets\gpTools\exact copy of.xslt'))
# temporary XML file
xmlfile = arcpy.CreateScratchName('.xml',workspace=arcpy.env.scratchFolder)
# export xml
arcpy.XSLTransform_conversion(fcPathName, copy_xslt, xmlfile, '')
# get the tree object and root element from the exported xml file
tree = ET.parse(xmlfile)
root = tree.getroot()
# get the dataIdInfo element
dataIdInfoEl = root.find('dataIdInfo')
# dataIdInfo purpose element
# Create the needed purpose xml element
subEl = ET.SubElement(dataIdInfoEl,'idPurp')
subEl.text = df_row['FULL_NAME']
num_elements += 1
# dataIdInfo abstract element
# Create the needed abstract xml element
subEl = ET.SubElement(dataIdInfoEl,'idAbs')
subEl.text = df_row['ABSTRACT']
num_elements += 1
# import the thumbnail image (jpg) from a file folder by name. Thumbnail file must exist (created by a separate process)
thumbnailsPath = 'c:/thumbnails/'
jpgFile = thumbnailsPath + featName + '.jpg'
if os.path.exists(jpgFile):
with open(jpgFile, "rb") as img_file:
strEncoded = base64.b64encode(img_file.read())
# Create the needed thumbnail xml element
attrib = {'EsriPropertyType':'PictureX'}
subEl = ET.SubElement(root,'Binary')
subEl = ET.SubElement(subEl,'Thumbnail')
subEl = ET.SubElement(subEl,'Data', attrib)
subEl.text = strEncoded
num_elements += 1
if num_elements > 0:
# save modifications to XML
tree.write(xmlfile)
arcpy.MetadataImporter_conversion(xmlfile, fcPathName)
else:
print('No changes to save')
... View more
11-12-2019
12:25 PM
|
0
|
0
|
1348
|
POST
|
Thanks for the links Dan. I found the answer I was looking for here. https://community.esri.com/message/890233-re-embed-a-thumbnail-in-xml-for-item-description?commentID=890233&et=watches.email.thread#comment-890233 Harlan Marshall GIS Analyst – Senior Pima County (520) 724-6757
... View more
11-12-2019
07:04 AM
|
0
|
0
|
1348
|
POST
|
Thanks for your answer. I was actually looking for a programmatic way to update metadata. Harlan Marshall GIS Analyst – Senior Pima County (520) 724-6757
... View more
11-12-2019
07:01 AM
|
0
|
0
|
1348
|
POST
|
Our environment(in case it matters): Windows Server 2016 Standard, ArcGIS Desktop 10.6.1, SQL Server 2017 Standard, Python 2.7 We have an enterprise SQL Server geodatabase functioning as a read-only library of GIS data that is refreshed nightly with changes from a versioned geodatabase. When a feature class is updated, the feature class is replaced in the library geodatabase and metadata must be recreated for it there. We have lots of user created metadata for each feature class that is maintained in a SQL Server table. After the feature class is replaced in the library geodatabase we export the auto-generated metadata on the updated library feature class to an xml file, modify the exported xml with values from our metadata table, and import it back into the library feature class. I've worked through the python code needed to do all that but I'm stuck on the issue of getting the thumbnail images from a folder of regularly updated jpeg files into the xml file for export to the library feature class metadata. Can anyone please help with how this can be done programmatically without manually using the metadata editing tools in ArcCatalog one at a time. We refresh over a hundred feature classes every day.
... View more
11-08-2019
08:39 AM
|
0
|
5
|
1553
|
POST
|
Getting started with API for Python and Jupyter Notebook. Using ArcGIS pro 2.2 with Arcgis 1.5.2 python package. I can get the map widget to display from GIS object connecting to https://www.arcgis.com. Doing the same thing from GIS object connecting to our own enterprise portal https://pimadevportal.pima.gov/arcgis does not display the map widget (arrow below points to missing map widget). The cell executes without error but no map displays. The gis_pc GIS object can be searched for feature classes successfully so I know it's connected and working. Any ideas where to look to solve this issue? Our dev portal has a default basemap assigned and I can generate a map in ArcGIS Pro project.
... View more
12-12-2018
09:10 AM
|
0
|
0
|
252
|
POST
|
Thanks Joshua for the answer. I can use arcpy with Jupyter Notebook but do not get widgets for result display other than textual.
... View more
11-29-2018
11:30 AM
|
0
|
0
|
618
|
POST
|
Can I make a direct connection to our SQL Server enterprise geodatabases with API for Python? Does the API only work with AGOL or Portal?
... View more
11-29-2018
11:07 AM
|
0
|
2
|
947
|
POST
|
Your solution works perfectly. I can't utilize an identity field in the database to increment the numbers because the case number is a text concatenation of the year and a sequence number which starts over at the beginning every year (like 18-006). Thanks for your help Sean!
... View more
01-03-2018
07:58 AM
|
0
|
0
|
447
|
POST
|
Working with ArcGIS Desktop 10.5.1 and .NET SDK. Building ArcMap add-in extension. I'm trying to cause a newly created feature to be saved programatically as the last operation of the OnCreateFeature edit event. The problem I'm having is that when the save edit command completes, another feature is created and the OnCreateFeature event is fired again. I do not understand what is causing another feature to be created. Here's the important parts of my OnCreateFeature event handler: private void m_editEvents_OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
{
IFeature pFeature = obj as IFeature;
// Set feature case number and other stuff...
// Save the newly created feature so that the feature and case number is commited
UID pUID = new UID();
pUID.Value = "{59D2AFD2-9EA2-11D1-9165-0080C718DF97}"; // esriEditor.SaveEditsCommand
ICommandItem pCmdItem = ArcMap.Application.Document.CommandBars.Find(pUID, false, false);
pCmdItem.Execute();
}
I know that the SaveEditsCommand internally executes StopEditing and StartEditing. However, I do not see why another feature is created and goes into endless loop (create, save, create, save, on and on). If there is a better way to accomplish saving automatically on creation, I would appreciate greatly finding out how to do it. The reason I need this to happen is to commit the feature with its calculated case number to the geodatabase instantly so that other concurrent editors can get the next available sequential number from the feature class itself.
... View more
01-02-2018
10:50 AM
|
0
|
2
|
557
|
POST
|
I'm posting this as a discussion in hopes of helping someone else that encounters this same issue. I have already found a workaround so this is not a question. I'm using ArcGIS Desktop 10.5.1 trying to enable editor tracking on all feature class datasets in a 10.5.1 enterprise geodatabase. The datasets are all registered as versioned. They also all have archiving enabled. I am connecting to the database as the owner in ArcCatalog 10.5.1.. If I right-click a dataset, choose Manage and click Enable Editor Tracking, it will succeed using the default field names, create fields if they don't exist, and save times in UTC, none of which works for our situation because we already have fields for last edit name and date which have been populated by a custom ArcMap extension. Nor do we want UTC time. Because we do not want the defaults, I've tried every possible way to use the Enable Editor Tracking tool but it always throws "ERROR 001216: Editor Tracking not supported for dataset blah-blah". This is not correct because the geodatabase version is 10.5.1. The workaround, which is not discussed in any ESRI Editor Tracking help pages that I could find, is to use the Editor Tracking tab in each feature class's properties page. There I can successfully set the tracking fields and set the time format. Rather painful for lots of feature classes but the tool does not work for me. Hope this saves someone the time it cost me to figure this out.
... View more
12-22-2017
09:34 AM
|
3
|
5
|
4204
|
POST
|
I'm creating an ArcMap extension to listen for onCreateFeature events and set an attribute value on the new feature. I want the user to get an ok/cancel dialog that will either proceed to create the feature or cancel the feature creation based on the user response. private void m_editEvents_OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
{
IFeature pFeature = obj as IFeature;
if (pFeature != null) // will never be null on create new feature
{
// get the new feature's table name
ITable tbl = pFeature.Table as ITable;
IDataset dataset = tbl as IDataset;
string sTblName = dataset.Name.Split('.')[2].ToLower();
// Implement user OK or Cancel message box
bool resp = GetOKCancelResponse("Creating New " + sTblName.ToUpper() + " Feature", "Do you want to create a new " + sTblName + " point?");
if (resp == false)
{
//Cancel the operation
}
else
{
// do important stuff
}
}
}
private bool GetOKCancelResponse(string caption, string message)
{
bool rslt = false;
var result = MessageBox.Show(message, caption,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question);
// If the no button was pressed ...
if (result == DialogResult.OK)
rslt = true;
return rslt;
}
... View more
07-06-2017
04:07 PM
|
0
|
2
|
625
|
POST
|
You’re correct. I had just figured that out and was ready to reply. It works great. Thanks for your fast response and great answers. Harlan Marshall GIS Analyst – Senior Pima County (520) 724-6757
... View more
06-19-2017
04:21 PM
|
0
|
0
|
2184
|
POST
|
This works. Thank you! Since IE doesn't support the "=>" function syntax, I'm trying to replace the selection of intersecting feature code with older javascript syntax ( foo => {function code} replace with function(foo) {function code}) but it returns no intersections with the older syntax. Can you tell what's wrong with my change below? // intersect overlay polygons
featureLayer.load().then(function(fl) {
featureLayer.queryFeatures().then(function (results) {
let allPolygons = results.features;
// This does not work
gIntersects = allPolygons.filter(function (graphic) { geometryEngine.intersects(graphic.geometry, parcelGeometry) });
// This works
gIntersects = allPolygons.filter(graphic => geometryEngine.intersects(graphic.geometry, parcelGeometry));
});
});
... View more
06-19-2017
03:10 PM
|
0
|
2
|
2184
|
POST
|
I'm using API 4.3. You're answer is helpful but I should have mentioned that there is no client map involved. Without a map there is no layerView, graphics, etc. I'm creating a script that will intersect a land parcel geometry with an array of all polygon geometries in another feature class for the purpose of determining information about the intersecting polygons (attributes) and percentages of the parcel area that are intersected by each polygon. The user searches for a parcel, then chooses a polygon feature class to overlay with and receives tabular data about the polygons intersecting the parcel. Thanks for your help.
... View more
06-19-2017
09:49 AM
|
0
|
4
|
2184
|
Title | Kudos | Posted |
---|---|---|
3 | 12-22-2017 09:34 AM | |
1 | 01-25-2017 08:35 AM |
Online Status |
Offline
|
Date Last Visited |
06-08-2021
12:30 PM
|