I'm working on coding a function in ArcGIS trying to measure the number of pixels between a point (feature class) and its nearest building horizontally within a UDEM raster, then return the number.

Here is my idea:

  1. Execute Zonal Statistics as Table and create a cursor to see whether the value in output table equals 0(the elevation of ground in my UDEM are set to 0 while elevation of building remain the real value)
  2. If so(value=0), make x coordinate plus one, which means move the point 1 meter to the right(the resolution is 1×1) and refresh the coordinate of the point.
  3. Iterate over step2 until the value doesn't equal 0,thus showing the location of point has moved to the "boundary" and I'll know the distance.

My problem now is having no idea how to perform Step2.

I tried some code to change its location but doesn't work.

closed as off-topic by PolyGeo Aug 18 '18 at 19:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • The point you want do move is a point in a feature class or only a geometry point? Could you add the rest of the code? – BERA Aug 17 '18 at 6:54
  • @BERA It's a feature class(created via Catalog-File Cnnection-New-Shapefile-point type and i edit its original location by mouse) – Joe.Z Aug 17 '18 at 7:02
  • 1
    Please Edit the question in response to requests for clarification. It's not fair to those who would answer to need to mine the comments for critical information. Your description of your process is incomplete, since altering a memory object has no impact on the data source without other steps. – Vince Aug 17 '18 at 7:51

To move a point in a feature class you can use the da.UpdateCursor and SHAPE@XY token. Select the point/points you want to move and then:

import arcpy
in_features = 'Pointlayer' #Change to match your layer name
x_shift = 1
y_shift = 1
with arcpy.da.UpdateCursor(in_features, ['SHAPE@XY']) as cursor:
    for row in cursor:
        cursor.updateRow([[row[0][0] + (x_shift),
                           row[0][1] + (y_shift)]])

With no selection all points will be moved. Backup your data before you try the code.

enter image description here

  • Thanks,but how to "select the point you want to move" when there're more than one in the layer? Shouldn't the code works for whole layer?By mouse-clicking? – Joe.Z Aug 17 '18 at 7:37
  • 1
    @Joe.Z Like i said if you dont select a point all will be moved. Your original question is unclear, add a complete code snippet – BERA Aug 17 '18 at 7:42
  • Sorry I haven't finished the complete function code coz I couldn't settle Step2 before.I post the whole function idea just to clarify the use of it in case people get me wrong. – Joe.Z Aug 17 '18 at 8:06
  • you can use arcpy select by location or select by attribute to select the desired points – NULL.Dude Aug 17 '18 at 12:18
  • @Joe.Z if you have another question post it as a new one. The searchcursor is looping every Point in the layer – BERA Aug 21 '18 at 8:01

This is the case when raster solution is way faster and much more efficient. To implement it, convert your buildings to raster using any field, and:

arcpy.gp.RasterCalculator_sa('Con(IsNull("BUILDING_RASTER"),1,0)', "../Flow_Dir")
arcpy.gp.FlowLength_sa("Flow_Dir", "../FlowLength", "DOWNSTREAM", "")
arcpy.gp.EucDistance_sa("EASTERN BORDER", "../distance")

Sample both rasters to points table and compute difference between values in Distance and FlowLength fields. Points with 0 difference have no buildings to the East of them:

enter image description here

To compute distance West from points, change parameter in flow direction to UPSTREAM and replace DISTANCE by max(Distance)-Distance. Credits go to whuber, most certainly this was in one of his solutions, that I struggle to find.


To modify coordinates of a point, you just need to set its X or Y properties:

pointGeometry.X += 1

or, create a new point object:

newPoint = arcpy.Point(pointGeometry.X + 1, pointGeometry.Y)

See the relevant documentation here: https://pro.arcgis.com/en/pro-app/arcpy/classes/point.htm

  • I tyied with the following code: p=arcpy.Point(21374420,4306120) pointgeo=arcpy.PointGeometry(p) newPoint = arcpy.Point(pointgeo.X + 1, pointgeo.Y) but I got an error said:**AttributeError: 'PointGeometry' object has no attribute 'X' ** Did I forget to set the attribute ?or any possible mistake? – Joe.Z Aug 18 '18 at 7:45
  • With the limited amount of information we have now, it's hard to say. It would be helpful if you'd add the relevant pieces of code to your original question. – Berend Aug 18 '18 at 8:35

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