Tom,<br><br>Can you check the destination shapefile with &#39;ogrinfo&#39; and see if it works?<br>If ogrinfo gives a valid output of the new file, check with &#39;ogrinfo -al&#39; and compare it with the old file&#39;s output.<br>
( <a href="http://www.gdal.org/ogrinfo.html">http://www.gdal.org/ogrinfo.html</a> )<br><br><div class="gmail_quote">On Wed, Aug 4, 2010 at 6:57 PM, Tom Jeffery <span dir="ltr">&lt;<a href="mailto:tjeffery@gmail.com">tjeffery@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
I&#39;m working with GDAL&#39;s Java bindings, and trying to simply add an index<br>
field to a shapefile.  This is working, but the resulting shapefile gets<br>
corrupted somehow, where viewing it in ArcMap causes the message &quot;Warning,<br>
inconsistent extent.&quot; and viewing it in ArcCatalog shows all the points in<br>
the shapefile in the very upper left corner of the preview.  (Viewing the<br>
metadata tab in ArcCatalog will crash the program.)<br>
<br>
Below is the method where I&#39;m adding the index field... is there anything<br>
I&#39;m missing / obviously wrong here?  Any help would be greatly appreciated!<br>
<br>
Thanks,<br>
-Tom Jeffery<br>
<br>
        public static void addIndex(File input, String fieldName) throws Exception<br>
{<br>
                ogr.RegisterAll();<br>
                DataSource dataSource = ogr.Open(input.getAbsolutePath(), true);<br>
<br>
                if (dataSource == null) {<br>
                        throw new Exception(&quot;Error opening input file while trying to add<br>
index.&quot;);<br>
                }<br>
<br>
                // Shapefiles have a single layer<br>
                Layer layer = dataSource.GetLayer(0);<br>
<br>
                // Creating an OFTInteger alone didn&#39;t seem to do the trick, but setting<br>
the width to 9 created a &quot;Long Integer&quot;<br>
                // field (as viewed in ESRI)<br>
                FieldDefn newField = new FieldDefn(fieldName, ogr.OFTInteger);<br>
                newField.SetWidth(9);<br>
                int result = layer.CreateField(newField);<br>
                if (result != ogr.OGRERR_NONE)<br>
                        throw new Exception(&quot;Got OGR error code: &quot; + result + &quot; when trying to<br>
add new field to shapefile.&quot;);<br>
<br>
                for (int i = 0; i &lt; layer.GetFeatureCount(); i++) {<br>
                        org.gdal.ogr.Feature feature = layer.GetFeature(i);<br>
                        feature.SetField(fieldName, i);<br>
                        layer.SetFeature(feature);<br>
                        feature.delete();<br>
                }<br>
                // you must call &quot;delete&quot; (or Destroy in c/c++) to properly close / write<br>
the datasource..<br>
                layer.delete();<br>
                dataSource.delete();<br>
        }<br>
<font color="#888888">--<br>
View this message in context: <a href="http://osgeo-org.1803224.n2.nabble.com/gdal-dev-Editing-attributes-with-ogr-causing-corrupt-shapefile-tp5372483p5372483.html" target="_blank">http://osgeo-org.1803224.n2.nabble.com/gdal-dev-Editing-attributes-with-ogr-causing-corrupt-shapefile-tp5372483p5372483.html</a><br>

Sent from the GDAL - Dev mailing list archive at Nabble.com.<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br>/tʃaɪθənjə/ /kʊmɑr/ <br>+91-9494447584<br>17.2416N 80.1426E<br>