<?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 Re: Moving shape files based on attribute values programatically ? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624321#M48684</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear MC,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Apologies for missing out a significant point on your post dated 07-16-2012 07:12 AM.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My buildings are not as points , but as Polygons. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can either &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 - create centroids for these building polygons AS POINTS and use your code ( which is only partial fulfilment)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2- Or move the polygons programmatically to the Administrative Centroids.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I am not demanding too much, I would like MCusumanos or other experts view on this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks to all again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Jul 2012 17:16:35 GMT</pubDate>
    <dc:creator>AdarshMadhavan</dc:creator>
    <dc:date>2012-07-19T17:16:35Z</dc:date>
    <item>
      <title>Moving shape files based on attribute values programatically ?</title>
      <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624315#M48678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi ESRI geeks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How to approach the below problem programmatically ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have two sets of shape files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One shape file is georeferenced and has got information of all administrative boundaries with certain code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another set is buildings whose name is same as a value in the attribute table of the parent boundaries they should be contained in, but Non-georeferenced.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can I move these buildings to the boundaries based on the attribute table name ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;intellgis&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Jul 2012 11:50:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624315#M48678</guid>
      <dc:creator>AdarshMadhavan</dc:creator>
      <dc:date>2012-07-15T11:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Moving shape files based on attribute values programatically ?</title>
      <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624316#M48679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can I do something with update cursor ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Jul 2012 14:24:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624316#M48679</guid>
      <dc:creator>AdarshMadhavan</dc:creator>
      <dc:date>2012-07-15T14:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Moving shape files based on attribute values programatically ?</title>
      <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624317#M48680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If it is OK to have the buildings stacked as a single point in the center of their respective administrative polygons, you could run this process:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Convert all administrative polygons to points using Feature to Point tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) Calculate X / Y values on administrative boundary points.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3) Calculate new field in your buildings feature to equal feature name (administrative code) : see &lt;/SPAN&gt;&lt;A href="http://mappingcenter.esri.com/index.cfm?fa=ask.answers&amp;amp;q=1529" rel="nofollow noopener noreferrer" target="_blank"&gt;http://mappingcenter.esri.com/index.cfm?fa=ask.answers&amp;amp;q=1529&lt;/A&gt;&lt;SPAN&gt; (9.3, you may need to research how to do this in 10)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3) Join your buildings feature with administrative boundaries feature based on administrative code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4) Export Join, which will now have admin X / Y.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5) Right click the "SHAPE" field in your newly exported feature, select Python, click "Show Codeblock" and enter the following into the Pre-Logic Script Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def XYsetVALUE( shape, X_value, Y_value):
&amp;nbsp;&amp;nbsp; point = shape.getPart(0)
&amp;nbsp;&amp;nbsp; point.X = X_value
&amp;nbsp;&amp;nbsp; point.Y = Y_value
&amp;nbsp;&amp;nbsp; return point&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enter the following into the "Shape" box:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;XYsetVALUE ( !SHAPE!, !X!, !Y! )&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Click OK. Your building points will move to their respective administrative boundaries.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:35:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624317#M48680</guid>
      <dc:creator>MarcCusumano</dc:creator>
      <dc:date>2021-12-12T02:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Moving shape files based on attribute values programatically ?</title>
      <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624318#M48681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear MCusumano,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; I appreciate the answer and solution - yet to check it though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; +1 for you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Intellgis&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 14:19:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624318#M48681</guid>
      <dc:creator>AdarshMadhavan</dc:creator>
      <dc:date>2012-07-17T14:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Moving shape files based on attribute values programatically ?</title>
      <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624319#M48682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear MCusumano,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I nearly executed the program to perfection , but at the final stage, the Python Geoprocessing code wont work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Possible Reason 1 -the centroid x and centroid y field names are POINT_X and POINT_Y,&amp;nbsp; different from the code (point.x amd point.y ).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Solution : tried to change the code to match the field names.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Possible reason 2 - The building shape files have no cordinate system defined. Shall I try to define projection to the same CRS of the administrative boundaries/centroids ???&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the timely help again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 16:51:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624319#M48682</guid>
      <dc:creator>AdarshMadhavan</dc:creator>
      <dc:date>2012-07-17T16:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: Moving shape files based on attribute values programatically ?</title>
      <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624320#M48683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes set the coordinate system of the buildings the same as the boundaries. To get the code to work, leave the Pre-logic script code the same and set the "Shape =" box to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;XYsetVALUE ( !SHAPE!, !POINT_X!, !POINT_Y! )&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jul 2012 11:18:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624320#M48683</guid>
      <dc:creator>MarcCusumano</dc:creator>
      <dc:date>2012-07-18T11:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Moving shape files based on attribute values programatically ?</title>
      <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624321#M48684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear MC,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Apologies for missing out a significant point on your post dated 07-16-2012 07:12 AM.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My buildings are not as points , but as Polygons. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can either &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 - create centroids for these building polygons AS POINTS and use your code ( which is only partial fulfilment)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2- Or move the polygons programmatically to the Administrative Centroids.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I am not demanding too much, I would like MCusumanos or other experts view on this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks to all again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 17:16:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624321#M48684</guid>
      <dc:creator>AdarshMadhavan</dc:creator>
      <dc:date>2012-07-19T17:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Moving shape files based on attribute values programatically ?</title>
      <link>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624322#M48685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried a VB script given by Dean Thevaos in the below forum &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=992&amp;amp;t=213078"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=992&amp;amp;t=213078&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is how you should do it. Make sure you are calculating the "Shape" field and you have a field named "XY" that contains the X and Y coordinates seperated by a comma. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pPolygon As IPolygon&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pArea As IArea&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pOrigin As IPoint&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim sXYField As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dXY() As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dX As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dY As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pTransform As ITransform2D&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;sXYField = [XY]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If (Not IsNull([Shape])) Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Set pPolygon = [Shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; dXY = Split(sXYField, ",")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; dX = CDbl(dXY(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; dY = CDbl(dXY(1))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; If (Not pPolygon.IsEmpty) Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pArea = pPolygon&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pOrigin = pArea.Centroid&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pTransform = pPolygon&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dX = dX - pOrigin.X&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dY = dY - pOrigin.Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pTransform.Move dX, dY&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;__esri_field_calculator_splitter__&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pPolygon&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This also giving me errors ! but a syntax error may be I will be able to solve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jul 2012 10:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-shape-files-based-on-attribute-values/m-p/624322#M48685</guid>
      <dc:creator>AdarshMadhavan</dc:creator>
      <dc:date>2012-07-20T10:39:41Z</dc:date>
    </item>
  </channel>
</rss>

