<?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 Reading the record values in several specific locations of a shapefile in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/reading-the-record-values-in-several-specific/m-p/442200#M34620</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello everyone!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;from osgeo import ogr

LandUse = ogr.Open("C:\\Python26\\ArcGIS10.0\\landuse shpfile (polygon)\\landuse.shp")
lyr = LandUse.GetLayerByName("landuse data_ypan")
lyr.ResetReading()
point = ogr.CreateGeometryFromWkt("POINT(503234.931458 3443753.43622)")
for feat in lyr:
&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = feat.GetGeometryRef()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if geom.Contains(point):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sm = feat.GetField(feat.GetFieldIndex("Land_Group"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print sm&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am wondering if there is the possibility to import variables X, Y in the place of the number coordinates (red coloured text) in order to perform a for loop among several x, y coordinates.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:29:27 GMT</pubDate>
    <dc:creator>irinivozinaki</dc:creator>
    <dc:date>2021-12-12T16:29:27Z</dc:date>
    <item>
      <title>Reading the record values in several specific locations of a shapefile</title>
      <link>https://community.esri.com/t5/python-questions/reading-the-record-values-in-several-specific/m-p/442200#M34620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello everyone!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;from osgeo import ogr

LandUse = ogr.Open("C:\\Python26\\ArcGIS10.0\\landuse shpfile (polygon)\\landuse.shp")
lyr = LandUse.GetLayerByName("landuse data_ypan")
lyr.ResetReading()
point = ogr.CreateGeometryFromWkt("POINT(503234.931458 3443753.43622)")
for feat in lyr:
&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = feat.GetGeometryRef()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if geom.Contains(point):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sm = feat.GetField(feat.GetFieldIndex("Land_Group"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print sm&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am wondering if there is the possibility to import variables X, Y in the place of the number coordinates (red coloured text) in order to perform a for loop among several x, y coordinates.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:29:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/reading-the-record-values-in-several-specific/m-p/442200#M34620</guid>
      <dc:creator>irinivozinaki</dc:creator>
      <dc:date>2021-12-12T16:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Reading the record values in several specific locations of a shapefile</title>
      <link>https://community.esri.com/t5/python-questions/reading-the-record-values-in-several-specific/m-p/442201#M34621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure what you mean by saying "import variables X Y". You want to prepare a list or read them from file or something.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If list is ok for you, then code below should work (assume that coords are floats). If you want to read them from file the simply prepare list from text file before for loop:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
points = []
f = open('C:\\coords.txt', 'r')
for line in f.readlines():
&amp;nbsp;&amp;nbsp;&amp;nbsp; x, y = [coord.strip() for coord in line.split(';')] #suppose coords are delimited with semicolons
&amp;nbsp;&amp;nbsp;&amp;nbsp; points.append((float(x), float(y)))
f.close()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;from osgeo import ogr

LandUse = ogr.Open("C:\\Python26\\ArcGIS10.0\\landuse shpfile (polygon)\\landuse.shp")
lyr = LandUse.GetLayerByName("landuse data_ypan")
lyr.ResetReading()
points = [(x1,y1), (x2, y2),...,(xn, yn)]
for coords in points:
&amp;nbsp;&amp;nbsp;&amp;nbsp; point = ogr.CreateGeometryFromWkt("POINT(%f %f)" % coords)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for feat in lyr:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = feat.GetGeometryRef()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if geom.Contains(point):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sm = feat.GetField(feat.GetFieldIndex("Land_Group"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print sm&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arek&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:47:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/reading-the-record-values-in-several-specific/m-p/442201#M34621</guid>
      <dc:creator>ArkadiuszMatoszka</dc:creator>
      <dc:date>2021-12-11T19:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reading the record values in several specific locations of a shapefile</title>
      <link>https://community.esri.com/t5/python-questions/reading-the-record-values-in-several-specific/m-p/442202#M34622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much for your help... it finally worked...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The only change that I have done is in:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;points = [(x1,y1), (x2, y2),...,(xn, yn)]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I changed that to the following: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;points=[(x,y)] &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;because of the fact that the code reads in every grid cell the (x, y) pair and as a result these pairs are always changing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2012 06:01:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/reading-the-record-values-in-several-specific/m-p/442202#M34622</guid>
      <dc:creator>irinivozinaki</dc:creator>
      <dc:date>2012-11-30T06:01:53Z</dc:date>
    </item>
  </channel>
</rss>

