RE: [OpenMap Users] shapefile header fields, File Length

From: Reese, Nathan <nreese_at_integrity-apps.com>
Date: Thu, 5 Nov 2009 10:32:00 -0500

Hi Don,

I have found the problem! The class ShpOutputStream.java calculates file content length by adding the position of the last record and the last record's content length. However, a record's content length does not include the record header. As a result, the file content length is always off by 4. After correcting the problem, ArgGIS had no problems ingesting the shapefile generated with OpenMap.

Attached is an updated version of ShpOutputStream.java containing the fixes (I only fixed the problem for shapefiles containing polygons). This is the first time I have ever found and fixed a bug in an OpenSource project. How do I submit my changes to the project?

Nathan

-----Original Message-----
From: Don Dietrick [mailto:dietrick_at_bbn.com]
Sent: Mon 10/26/2009 4:44 PM
To: Reese, Nathan
Cc: openmap-users_at_bbn.com
Subject: Re: [OpenMap Users] shapefile header fields, File Length
 
Hi Nathan,

I've just checked a couple of shape files that I've recently created via
the method outlined below and the header information seems reasonable,
and the reading code isn't complaining about file length mismatches.

- Don

Reese, Nathan wrote:
>
> Don,
>
> I have reworked my shapefile generation code to use the classes
> suggested. See the code fragment below.
>
> EsriGraphicList polygonList = new EsriPolygonList();
> DbfTableModel polygonModel = new DbfTableModel(7);
>
> //Build graphics
> while (ellipses to add) {
> OMEllipse ellipse = new OMEllipse(centerPoint, majorAxis,
> minorAxis, Length.NM, Math.toRadians(azimuth-90));
> float[] ellipsePoints = ellipse.createLatLonPoints();
> OMPoly polyGraphic = new OMPoly(ellipsePoints,
> OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE);
> polygonList.add(polyGraphic);
>
> ArrayList<String> attributes = new ArrayList<String>();
> ...
> polygonModel.addRecord(attributes);
> }
>
> //Write files
> EsriShapeExport ese = new EsriShapeExport(polygonList, polygonModel,
> "testShapefile");
> ese.export();
>
>
> The shapefile generated with the reworked method is identical to the
> shapefile generated with the original method, including the file
> length header field. Have you had a chance to dig into the length
> generation code and see if anything is amiss?
>
> Thanks,
>
> Nathan
>
>
> -----Original Message-----
> From: Don Dietrick [mailto:dietrick_at_bbn.com]
> Sent: Tue 10/20/2009 11:33 AM
> To: Reese, Nathan
> Cc: openmap-users_at_bbn.com
> Subject: Re: [OpenMap Users] shapefile header fields, File Length
>
> Hi Nathan,
>
> I admit I haven't tested this method of doing this, but your code
> looks like it should work. I'll give it a shot later.
>
> If I were going to create a shape file, I'd do something like this;
>
> OMGraphicList omgl = new OMGraphicList();
>
> ... add OMGraphics to omgl
>
> DbfTableModel dbf = new DbfTableModel(..);
>
> ... add entries appropriate for OMGraphics
>
> EsriShapeExport ese = EsriShapeExport(omgl, dbf, my_file_path);
> ese.export();
>
> - Don
>
> On Oct 20, 2009, at 10:44 AM, Reese, Nathan wrote:
>
> > I am creating a shapefile with polygons. Below is the code fragment
> > that I am using to generate a shapefile, I have omitted dbf and shx
> > code for simplicity. Let me know if you need any additional
> > information.
> >
> > EsriLayer polygonLayer = new EsriLayer("testShapefile",
> > ShapeConstants.SHAPE_TYPE_POLYGON, 7);
> >
> > //Build dbf table
> > ...
> >
> > //Build layer
> > while (ellipses to add to layer) {
> > OMEllipse ellipse = new OMEllipse(centerPoint, majorAxis,
> > minorAxis, Length.NM, Math.toRadians(azimuth-90));
> > float[] ellipsePoints = ellipse.createLatLonPoints();
> > EsriPolygon poly = new EsriPolygon(ellipsePoints, 1, 0);
> > ArrayList<String> attributes = new ArrayList<String>();
> > ...
> > polygonLayer.addRecord(poly, attributes);
> > }
> >
> > //Write file
> > FileOutputStream shpFileStream = new FileOutputStream
> > ("testShapefile.shp");
> > ShpOutputStream shpStream = new ShpOutputStream(shpFileStream);
> > EsriGraphicList list = polygonLayer.getEsriGraphicList();
> > int[][] imageData = shpStream.writeGeometry(list);
> >
> > //write dbf and shx files
> > ...
> >
> > shpFileStream.close();
> >
> >
> > Thanks,
> >
> > Nathan
> >
> > -----Original Message-----
> > From: Don Dietrick [mailto:dietrick_at_bbn.com]
> > Sent: Mon 10/19/2009 2:37 PM
> > To: Reese, Nathan
> > Cc: openmap-users_at_bbn.com
> > Subject: Re: [OpenMap Users] shapefile header fields, File Length
> >
> > Hi Nathan,
> >
> > The file length is calculated for the shapes being placed in the
> > file. What kind of shape type are you creating a file for, and what
> > classes are you using to do it?
> >
> > - Don
> >
> > On Oct 19, 2009, at 1:41 PM, Reese, Nathan wrote:
> >
> > > I am having problems opening shapefiles generated with OpenMap using
> > > various GIS applications (although the shapefile can be opened in GE
> > > and with ArcGIS). The shapefiles can only be opened by all GIS
> > > applications by first opening and resaving the file with ArcGIS.
> > >
> > > I have compared the orginal .shp file with the ArcGIS updated .shp
> > > and have found that the only difference is in the File Length field
> > > in the main file header (byte 27). I have tried using the ShapeFile
> > > class to display the shapefile header information, but that utility
> > > always returns a value of 100 for the File Length. Has any one
> > > experienced these types of problems. Does ShpOutputStream properly
> > > set the File Length field in the main file header?
> > >
> > > Thanks,
> > >
> > > Nathan
> > >
> >
> >
> >
> > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> > Don Dietrick, openmap_at_bbn.com
> > BBN Technologies, Cambridge MA, USA
> > http://openmap.bbn.com
> > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> >
> >
> >
> >
>
>







--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Nov 05 2009 - 10:33:12 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT