<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Zoltan<div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 07 Jul 2016, at 5:55 PM, Zoltan Szecsei <<a href="mailto:zoltans@geograph.co.za" class="">zoltans@geograph.co.za</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
  

    <meta http-equiv="content-type" content="text/html; charset=utf-8" class="">
  
  <div bgcolor="#FFFFFF" text="#000000" class="">
    Hi Everyone,<br class="">
    Maybe someone can give me a prod in the right direction?<br class="">
    <br class="">
    I have two Shape files (both polygons).<br class="">
    I'm trying to copy an attribute field value from B.shp into A.shp,
    using Lon and Lat from two of A.shp attribute fields to select the
    relevant polygon's attribute in B.shp.<br class="">
    <br class="">
    In other words:<br class="">
    <blockquote class="">A.shp attribute fields are:  "Name", "Longitude" and
      "Latitude"<br class="">
      B.shp attribute field is "Name"<br class="">
    </blockquote>
    Using the LatLong coords in the attribute fields of A.shp, I want to
    select a polygon in B.shp, and write that polygons "Name" contents
    into this A.shp's "Name" field.<br class="">
    <br class="">
    Is the field calculator up for this?<br class=""></div></div></blockquote><div><br class=""></div><div>I don't think so - its not really set up for doing inter-layer references. I wrote a few lines of python that will do it though (assumes you have two layers loaded with names a and b in the layers list:</div><div><br class=""></div><div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">reg = QgsMapLayerRegistry.instance()</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">a = reg.mapLayersByName('a')[0]</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">b = reg.mapLayersByName('b')[0]</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">collection = {}</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">index = QgsSpatialIndex()</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">for f in b.getFeatures():</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">   index.insertFeature(f)</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">   collection[f.id()] = f</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">with edit(b):</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">    for af in a.getFeatures():</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">        p = QgsPoint(af['lon'], af['lat'])</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">        box = QgsRectangle(p, p) </div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">        for key in index.intersects(box):</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">            feature = collection[key]</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">            print feature['name'], af['name'], af['lon'], af['lat']</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">            feature['name'] = af['name']</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">            b.updateFeature(feature)</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class="">Just paste that into the QGIS python console and it will update the name field of b with the value in a for the places where the attributes lon, lat in a intersect b.</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class="">Please test in a sandbox before trying on your production data....</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class="">Regards</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class="">Tim</div></div><br class=""><blockquote type="cite" class=""><div class=""><div bgcolor="#FFFFFF" text="#000000" class="">
    I've been trying to find ways of reference fields in separate maps
    (layers), but neither Google or I are winning at this.<br class="">
    <br class="">
    Regards, and TIA,<br class="">
    Zoltan<br class="">
    <br class="">
    <br class="">
    <br class="">
    <br class="">
    <br class="">
    <pre class="moz-signature" cols="72">-- 

===========================================
Zoltan Szecsei PrGISc [PGP0031]
Geograph (Pty) Ltd.
GIS and Photogrammetric Services

P.O. Box 7, Muizenberg 7950, South Africa.

Mobile: +27-83-6004028
Fax:    +27-86-6115323     <a class="moz-txt-link-abbreviated" href="http://www.geograph.co.za/">www.geograph.co.za</a>
===========================================</pre>
  </div>

_______________________________________________<br class="">Africa mailing list<br class=""><a href="mailto:Africa@lists.osgeo.org" class="">Africa@lists.osgeo.org</a><br class="">You can UNSUBSCRIBE at http://lists.osgeo.org/mailman/listinfo/africa</div></blockquote></div><br class=""></div></body></html>