<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Snap coordinates to closest raster cell center in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406222#M31982</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a coordinatess of one random point let's say XY = (412,992.581, 48,111.728) in meters in some local projected coordinate system. I would like to obtain the coordinates of the closest raster cell center X1Y1 and snap (change) the first coordinates to the same values.&amp;nbsp; Is this even possible?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Jul 2014 22:00:28 GMT</pubDate>
    <dc:creator>GrljAles</dc:creator>
    <dc:date>2014-07-28T22:00:28Z</dc:date>
    <item>
      <title>Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406222#M31982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a coordinatess of one random point let's say XY = (412,992.581, 48,111.728) in meters in some local projected coordinate system. I would like to obtain the coordinates of the closest raster cell center X1Y1 and snap (change) the first coordinates to the same values.&amp;nbsp; Is this even possible?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 22:00:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406222#M31982</guid>
      <dc:creator>GrljAles</dc:creator>
      <dc:date>2014-07-28T22:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406223#M31983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not in raster world, however a combination of&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001200000007000000"&gt;Raster to point&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00080000001q000000"&gt;Near Tool&lt;/A&gt;&lt;/P&gt;&lt;P&gt;might be a workaround.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 23:28:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406223#M31983</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-07-28T23:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406224#M31984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have done something like that in the past, but not in Python so I dont have any code example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will need the origin of the raster, number of columns and rows as well as cell size. Get those with arcpy.Describe&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The cell (column, row) can then be calculated as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;column = int(randomPointX - originX/cellsize)&lt;/P&gt;&lt;P&gt;row = int(randomPointY - originY/cellsize)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The cell center is then:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;centerX = originX + (column*cellsize) + 0.5*cellsize&lt;/P&gt;&lt;P&gt;centerY = originY + (row*cellsize) + 0.5*cellsize&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly you can assign these coordinates to your random point (or create a new).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps, otherwise, just ask.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Carsten&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 08:51:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406224#M31984</guid>
      <dc:creator>CarstenBøcker1</dc:creator>
      <dc:date>2014-07-29T08:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406225#M31985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Code examples are provided in the links I provided.&amp;nbsp; Arcpy can access the functionality of the provided tools without having to develop first-principles coding access to the data&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 08:56:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406225#M31985</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-07-29T08:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406226#M31986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Carsten and Dan, Thank you for your help. Really like your solution and I was just about post my solution that is very similar if not the same and ask if it would work in any case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you evalute and comment please:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First I round the coordinates down to the nearest integer. I believe that "math&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;trunc&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;&lt;/SPAN&gt;()" will do that.&lt;/P&gt;&lt;P&gt;Second, divide by cell size and round down the result to the nearest integer.&lt;/P&gt;&lt;P&gt;Third, multiply by cell size. The result are the coordinates of the lower left corner of the corresponding cell.&lt;/P&gt;&lt;P&gt;And finally add the1/2 of the cell size to the coordiantes from the third step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you explain why have you subtracted the origin coordinates from the random coordinates?&lt;/P&gt;&lt;P&gt;Will this work in any situation on any raster in any coorddinate system?&lt;/P&gt;&lt;P&gt;What if the coordinates were in decimal degrees?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again thank you for your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aleš&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 10:16:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406226#M31986</guid>
      <dc:creator>GrljAles</dc:creator>
      <dc:date>2014-07-29T10:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406227#M31987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your procedure looks like overkill when you can obtain them using the procedure I described.&amp;nbsp; In any event, you should be working with projected data, rounding decimal degree coordinates produces different planar differences depending on your poleward location&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 10:27:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406227#M31987</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-07-29T10:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406228#M31988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ales,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As far as I can see, your procedure is the same as mine. I would not however, round the ccordinates of the random point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I subtracted the origin coordinates in order to get the cell coordinate (column row)in relation to the rasters origin. But you are correct that it might not be necessary in this case, as you don't need the (column, row), but only the center coordinate. That depend whether your raster cells aligns with cells with origin (0,0) in your coordinate system.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The method above will not work with decimal degrees, only projected coordinate systems. In this case I would do as Dan suggests.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just remember that you will need a Desktop Advanced license in order to use the Near tool. As an alternative you could check out the spatial operators on geometries. I think there is a geometry.Near(anotherGeometry). I think i would also consider extracting the area just around the random point in the raster before Raster to Points in order to cut down the number of points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Carsten&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 10:50:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406228#M31988</guid>
      <dc:creator>CarstenBøcker1</dc:creator>
      <dc:date>2014-07-29T10:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406229#M31989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also try a Spatial Join rather than the Near tool if you don't have the appropriate license&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 11:01:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406229#M31989</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-07-29T11:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406230#M31990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good suggestion. I sometime get so absorbed in programming that I forget the standard tools &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, check out the spatial operators anyway. The are incredibly effective (and fun). I have had big performance improvements compared to standard tools.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Carsten&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 11:11:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406230#M31990</guid>
      <dc:creator>CarstenBøcker1</dc:creator>
      <dc:date>2014-07-29T11:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406231#M31991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Carsten, I've decided to try your method drom the third post but I can't get the origins. I've been searching the help but no succes. Would you be so kind and direct me to the correct page.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you both for your help, as I said for now I'm going to try with Carsten's method as I would like to do this in, I don't know how to say this, "calculational" way:) just for exercise to learn some thing about Python and programming. However I will definitly try the other methods too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aleš&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 19:05:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406231#M31991</guid>
      <dc:creator>GrljAles</dc:creator>
      <dc:date>2014-07-29T19:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: Snap coordinates to closest raster cell center</title>
      <link>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406232#M31992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nevermind, figured it out at last!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aleš&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 19:40:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/snap-coordinates-to-closest-raster-cell-center/m-p/406232#M31992</guid>
      <dc:creator>GrljAles</dc:creator>
      <dc:date>2014-07-29T19:40:42Z</dc:date>
    </item>
  </channel>
</rss>

