1

I downloaded a kmz field and converted it to a GDB fc on arcmap.

However, the field I need to label the layer by is stored in the pop-up html field...

It looks like this:

<html xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<head>
<META http-equiv="Content-Type" content="text/html">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body style="margin:0px 0px 0px 0px;overflow:auto;background:#FFFFFF;">
<table style="font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-collapse:collapse;padding:3px 3px 3px 3px">
<tr style="text-align:center;font-weight:bold;background:#9CBCE2">
<td>Benchmark: 100</td>
</tr>
<tr>
<td>
<table style="font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-spacing:0px; padding:3px 3px 3px 3px">
<tr>
<td>Point ID</td>
<td>100</td>
</tr>
<tr bgcolor="#D4E4F3">
<td>Type</td>
<td>Vertical</td>
</tr>
<tr>
<td>Northing</td> 
<td>2119938</td>
</tr>
<tr bgcolor="#D4E4F3">
<td>Easting</td>
<td>533366</td>
</tr> 
<tr>
<td>Elevation (NAVD88)</td>
<td>6.1 ft</td>
</tr>
<tr bgcolor="#D4E4F3">
<td>Elevation (NGVD29)</td>
<td>7.18 ft</td>
</tr>

All I need is the benchmark number (Benchmark: 100) from each field

Is there a way to either extract fields from the popup field OR create a new field based on the sorted popup field?

Tried a bit of the code here: How to populate Unique ID field after sorting?

but did not get anywhere.

1
  • It may help if you were to click the edit button under your question and add a sample of your pop-up html field's contents. Someone may be able to help you write an expression that would help parse the fields out of the pop-up, but having some sample content from you would greatly help in ensuring it met your particular needs and actually answered your question. Please edit so the community can best assist you.
    – John
    Commented Mar 18, 2014 at 16:01

1 Answer 1

1

I tried something similar in the python IDLE but haven't actually tested it within ArcDesktop/field calculator, so if there are any issues, feel free to leave a comment and I'll see what I can do to help, but you should be able to just use an expression along the lines of:

!FieldNameGoesHere!.split("<td>Benchmark: ")[1].split("</td>",1)[0]

Now, that script works for your particular example text above to return the benchmark value. So, in that case what you would want to do is just create a new field (name it benchmark or whatever you want) and then run field calculator on that new field using the above expression (obviously inserting the field name of the field that contains the pop-up-content you provided the sample of above).

Here's the warning I'll give you though: I DON'T KNOW OFF THE TOP OF MY HEAD IF THIS WILL WORK CORRECTLY IF EVERY RECORD DOES NOT HAVE A BENCHMARK VALUE SO USE WITH CAUTION!!! If not every record is going to have a benchmark in it and everything in that exact context as your example text above shows, you may instead want to try something like:

In the pre-script code block

def getBenchmark(a):
    try:
        return a.split("<td>Benchmark: ")[1].split("</td>",1)[0]

    except:
        return None

Than in the actual expression field

getBenchmark(!FieldNameGoesHere!)

That would go and populate the calculated field with the benchmark value for all of the records that have one, and leave that field null for all the records that don't have a benchmark value instead of causing an error.

Again, as I said, I hope this works for you and makes sense, but if not, feel free to leave a comment and I can try to help if I am able.

EDIT:

Ok, so apparently, after much frustration and research (I've got a similar situation I'd like to have a functional workflow for, so it's not just for this question), I've realized you can't work with multi-line text values with the python parser in ArcGIS's Calculate Field GP Tool. I don't know all the details of why, but apparently this is a known limitation within the software. Their recommendation is to use an update cursor, which I wouldn't argue with. However, I've never really done that much yet with cursors and I like being able to put things in model builder rather than always having to use a straight python script, so I figured out, more or less, a solution using the VB parser that should do the same thing as the python solution above, except it will handle multi-line text input correctly.

In Pre-Script Code Block:

Dim getValue
If InStr( [PopupInfo] ,"<td>Benchmark: ")>0 Then
x = Right( [PopupInfo] ,Len( [PopupInfo] )-(InStr( [PopupInfo] ,"<td>Benchmark: ")+(Len("<td>Benchmark: ")-1)))
getValue = Left(x,InStr(x,"</td>")-1)

else
getValue = ""
end if

In the expression

getValue

For this way to work, you should just have to create a new field to calc the values into and run this script against it (of course you need to go through the code and replace the field name in the 4 places where it appears in the code block, replace it with your source field's name). The only other difference is that if there is no benchmark value, instead of populating with a null field it will populate with an empty string (not that different but an empty string I think takes up a little bit more storage space). Anyway, I got that to work correctly on my own data set that had a multi-line text with similar content, so... hope it helps.

13
  • I really appreciate the help but neither worked... Here is the error message for both codes: Solution This error code covers a number of Python errors: Example error 1: exceptions.TypeError: cannot concatenate 'str' and 'int' objects. The above is a Python-specific error. The calculation is attempting to add or concatenate a string and a number. Example error 2: Invalid field shape@distance The above is an error using the geometry object. The distance method is not a valid method of the geometry object.
    – Tee
    Commented Mar 21, 2014 at 12:56
  • Ok, here would be something else to check then. What field type is the field you created that you are trying to calculate the benchmark value into? Also, are all of the benchmark values just numbers or do some of them include text as well? If the benchmark values include text and you're trying to put it in a short integer field, it's going to error out. Let me know.
    – John
    Commented Mar 21, 2014 at 14:08
  • Also, I'm guessing you did, but just double checking, did you set the parser to Python in the field calculator options or did you leave it as the default VB Script? It should only work as Python.
    – John
    Commented Mar 21, 2014 at 14:17
  • I tried both a short integer and string field- should I try another type? I am thinking the benchmark number pop up field includes the entire phrase 'Benchmark: 100'... so both. I'll try a string field again...
    – Tee
    Commented Mar 21, 2014 at 14:19
  • And yes- I set the parser to python
    – Tee
    Commented Mar 21, 2014 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.