<div dir="ltr"><div class="gmail-adn gmail-ads" style="border-left:none;padding:0px;display:flex;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:medium"><div class="gmail-gs" style="margin:0px;padding:0px 0px 20px;width:1043px"><div class="gmail-"><div id="gmail-:6bh" class="gmail-ii gmail-gt" style="font-size:12.8px;direction:ltr;margin:8px 0px 0px;padding:0px"><div id="gmail-:6bi" class="gmail-a3s gmail-aXjCH" style="overflow:hidden;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:small;line-height:1.5;font-family:Arial,Helvetica,sans-serif"><div dir="ltr">I am merging 2 or more Shapefiles pulled from OpenStreetMap.   In the merging, the values of fields are getting applied to the wrong output fields in the merged shapefile.   I have been looking at this code for a while and cannot figure out the error.  As a note, my downloaded source files don't all seem to have the exact same list of fields; not sure why.<div><br></div><div>As an example, the name field value from the source is assigned to the maxspeed value of the target.  This happens consistently for an entire source, so not random.<br><div><br></div><div>Code:</div><div><br></div><div><pre style="white-space:pre-wrap;background-color:rgb(248,248,255);color:rgb(0,0,0);font-family:Menlo;font-size:9pt"><span style="font-weight:bold">def </span><span style="color:rgb(153,0,0);font-weight:bold">copy_feature_attribute_values</span>(<span style="font-style:italic">inFeature</span>, <span style="font-style:italic">outLayerDefn</span>, <span style="font-style:italic">outFeature</span>)<span style="font-weight:bold">:<br></span><span style="font-weight:bold">  for </span>i <span style="font-weight:bold">in </span><span style="color:rgb(0,134,179)">range</span>(<span style="color:rgb(0,153,153)">0</span>, <span style="font-style:italic">outLayerDefn</span>.GetFieldCount())<span style="font-weight:bold">:<br></span><span style="font-weight:bold">    </span>fieldName <span style="font-weight:bold">= </span><span style="font-style:italic">outLayerDefn</span>.GetFieldDefn(i).GetNameRef()<br>    field <span style="font-weight:bold">= </span><span style="font-style:italic">inFeature</span>.GetField(i)<br>    <span style="font-style:italic">outFeature</span>.SetField(fieldName, field)</pre></div><div><pre style="white-space:pre-wrap;background-color:rgb(248,248,255);color:rgb(0,0,0);font-family:Menlo;font-size:9pt"><pre style="white-space:pre-wrap;font-family:Menlo;font-size:9pt"><i>... There is some code here to create the layer from the first of the<br></i></pre><pre style="white-space:pre-wrap;font-family:Menlo;font-size:9pt"><i> shapefiles to be merged</i></pre><pre style="white-space:pre-wrap;font-family:Menlo;font-size:9pt">la_streets_osm_layer_defn <span style="font-weight:bold">= </span>la_streets_osm_layer.GetLayerDefn()</pre></pre><pre style="white-space:pre-wrap;background-color:rgb(248,248,255);color:rgb(0,0,0);font-family:Menlo;font-size:9pt"><span style="font-weight:bold">for </span>sub_network_key <span style="font-weight:bold">in </span>sub_network_segments<span style="font-weight:bold">:</span></pre><pre style="white-space:pre-wrap;background-color:rgb(248,248,255);color:rgb(0,0,0);font-family:Menlo;font-size:9pt"><pre style="white-space:pre-wrap;font-family:Menlo;font-size:9pt">  sub_network_src <span style="font-weight:bold">= </span><span style="font-style:italic">config</span>[<span style="color:rgb(0,128,128);font-weight:bold">'SPATIAL'</span>][<span style="color:rgb(0,128,128);font-weight:bold">'BASE_STREET_PATH'</span>] <span style="font-weight:bold">+ </span><span style="font-style:italic">config</span>[<span style="color:rgb(0,128,128);font-weight:bold">'SPATIAL'</span>] \<br>                  [<span style="color:rgb(0,128,128);font-weight:bold">'CA_Street_Centerlines_OSM'</span>] <span style="font-weight:bold">+ </span>\<br>                  sub_network_key <span style="font-weight:bold">+ </span><span style="color:rgb(0,128,128);font-weight:bold">'/edges/edges.shp'</span></pre><pre style="white-space:pre-wrap;font-family:Menlo;font-size:9pt">  sub_network_ds <span style="font-weight:bold">= </span>ogr.Open(sub_network_src)<br>  sub_network_layer <span style="font-weight:bold">= </span>sub_network_ds.GetLayer()<br><br><span style="font-weight:bold">  for </span>sub_network_feature <span style="font-weight:bold">in </span>sub_network_layer<span style="font-weight:bold">:<br></span><span style="font-weight:bold">    </span>outFeature <span style="font-weight:bold">= </span>ogr.Feature(la_streets_osm_layer_defn)<br><br>    copy_feature_attribute_values(sub_network_feature, la_streets_osm_layer_defn, outFeature)<br>    newGeom <span style="font-weight:bold">= </span>sub_network_feature.GetGeometryRef()<br>    outFeature.SetGeometry(newGeom.Clone())<br><br>    la_streets_osm_layer.CreateFeature(outFeature)<br>    <span style="color:rgb(128,128,128)">outFeature </span><span style="font-weight:bold">= None<br></span><span style="font-weight:bold">    </span>la_streets_osm_layer.SyncToDisk()</pre></pre></div></div></div><div class="gmail-yj6qo"></div><div class="gmail-adL"></div></div></div><div class="gmail-hi" style="border-bottom-left-radius:1px;border-bottom-right-radius:1px;padding:0px;width:auto;background:rgb(242,242,242);margin:0px"></div></div></div><div class="gmail-ajx" style="clear:both"></div></div><div class="gmail-gA gmail-gt gmail-acV" style="font-size:12.8px;padding:0px;width:auto;border-bottom-left-radius:0px;border-bottom-right-radius:0px;border-top:none;margin:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif"><div class="gmail-gB gmail-xu" style="border-top:0px;padding:0px"><div class="gmail-ip gmail-iq" style="clear:both;margin:0px;padding:16px 0px;border-top:none"><div id="gmail-:6bg"><table class="gmail-cf gmail-wS" style="border-collapse:collapse"><tbody><tr><td class="gmail-amq" style="padding:0px 16px;vertical-align:top;width:44px"><img id="gmail-:0_450" name=":0" src="https://plus.google.com/u/0/_/focus/photos/public/AIbEiAIAAABECJmRnPPGv8PukwEiC3ZjYXJkX3Bob3RvKigwZTgwNWRhZjU0YzQwZTkyYzFiMDA0M2E4MzkzYzNlZmQ3N2RhMTdjMAGE0Pgf1KCimR_Ep1qLtqZjNgSRXg?sz=32" class="gmail-ajn gmail-bofPge" style="display: block; width: 32px; height: 32px; border-radius: 50%;"></td><td class="gmail-amr" style="padding:0px;width:1043px"><div class="gmail-nr gmail-wR" style="padding:0px;box-sizing:border-box;border-radius:1px;border:none;margin:0px"><div class="gmail-amn" style="color:inherit;height:auto;padding:0px;display:flex;line-height:20px"><span id="gmail-:6br" tabindex="0" class="gmail-ams gmail-bkH" style="border:none;display:inline-flex;font-family:"Google Sans",Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:0.875rem;letter-spacing:0.25px;background:none;border-radius:4px;box-sizing:border-box;color:rgb(95,99,104);height:36px;outline:none;padding:0px 16px 0px 12px;min-width:104px;margin-right:12px">Reply</span><span id="gmail-:6bt" tabindex="0" class="gmail-ams gmail-bkG" style="border:none;display:inline-flex;font-family:"Google Sans",Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:0.875rem;letter-spacing:0.25px;background:none;border-radius:4px;box-sizing:border-box;color:rgb(95,99,104);height:36px;outline:none;padding:0px 16px 0px 12px;min-width:104px;margin-right:12px">Forward</span></div></div></td></tr></tbody></table></div></div></div></div></div>