0

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.

3
  • 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
    Commented Aug 17, 2018 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.M
    Commented Aug 17, 2018 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
    Commented Aug 17, 2018 at 7:51

3 Answers 3

2

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

5
  • 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.M
    Commented Aug 17, 2018 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
    Commented Aug 17, 2018 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.M
    Commented Aug 17, 2018 at 8:06
  • you can use arcpy select by location or select by attribute to select the desired points
    – NULL.Dude
    Commented Aug 17, 2018 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
    Commented Aug 21, 2018 at 8:01
1

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.

0

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

2
  • 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.M
    Commented Aug 18, 2018 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
    Commented Aug 18, 2018 at 8:35

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