0

Calculate Field

I am getting an extent as "Value = -6281352.29789468 4551156.85895782 -6276072.29795601 4556436.85889649 NaN NaN NaN NaN" from Extent ({XMin}, {YMin}, {XMax}, {YMax}, {ZMin}, {ZMax}, {MMin}, {MMax}, {spatial_reference}).

For the evaluate Rule geo process I just need to trim the result to something like extent = "-6281352.29789468 4551156.85895782 -6276072.29795601 4556436.85889649".

Is there a way to trim in this geoprocessing tool Calcualte Value?

Passing the input as-is is passing something undefined causing Arc Pro to crash. I write click on the output variable "Extent" and add it as "Extent" instead of precondition when attaching it to Evaluate Rule Geoprocess.

2
  • return str(poly.extent.XMin) does return "Value = -6297192.298038766". If i can add ({XMin}, {YMin}, {XMax}, {YMax} into the same return statement i should be good (unless there is a string to double conversion issue with the tool evaluate rule.
    – prometheus
    Nov 16, 2022 at 17:38
  • 1
    Build the string you want from the properties of the extent object. Look at the help file on arcpy extent.
    – Hornbydd
    Nov 16, 2022 at 17:43

1 Answer 1

0

This solution meets the criteria, but the results are not accepted by the 'evaluate rule geoprocess'.

#Calculate Value geoprocess expression:

    getExtent(%OID for Polygon%)

#codeblock:
def getExtent(oid):
    sQuery = "OBJECTID = " + str(oid)
    with arcpy.da.SearchCursor("%grid_layer1447%", "SHAPE@", sQuery) as cursor:
        for row in cursor:
            extent = row[0].extent
            return ("{0} {1} {2} {3}".format(extent.XMin, extent.YMin, extent.XMax, extent.YMax))

model

message

calculate field edit

5
  • Shouldn't your extent numbers be just numbers that are separated by spaces? From the example: pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/…. Your current return string has something like, "XMin: 1, YMin: 2, XMax: 3, YMax: 4". Remove those descriptor texts like "XMin: " so that it's just "1 2 3 4". Also, please format your code to make it easier to read.
    – sushi
    Nov 16, 2022 at 21:21
  • Perfect, thank you. It looks like the extent is still being rejected with an Arc Pro crash from evaluate rule geoprocess as an input defined as extent (not precondition). I'll remove the str() and try again.
    – prometheus
    Nov 16, 2022 at 22:05
  • 1
    Remove your commas, the example in the link shows just spaces. Also be sure to change your output type to String since you're building the Extent with numbers instead of using an Extent object. If this is for Model Builder, posting your a screenshot of your Model would be helpful.
    – sushi
    Nov 16, 2022 at 22:10
  • Got the pics updated, got the commas removed. Still crashing pro (probably needing a double instead of a string), not sure how to pass this with the squery in the access cursor. Thanks :)
    – prometheus
    Nov 16, 2022 at 22:47
  • It would be best if you could edit your question and cut / paste these updates into the original post instead placing it in an answer. Also, I mentioned in the previous comment but change your data type to String since you are building a string and not using an Extent object.
    – sushi
    Nov 16, 2022 at 23:00

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.