[Gdal-dev] shifted objects in shapefiles

Ed McNierney ed at topozone.com
Tue Nov 15 11:19:15 EST 2005


Bart -

Thank - then disregard my advice <g>.  That sounds like a problem in the
creation of the shapefile, or in editing it.

Since you say you're not very familiar with shapefile internals, here's
the one-paragraph tutorial.  A shapefile is three files - .shp, .shx,
and .dbf.  All three files need to stay in sync with each other.  The
.shp file is essentially just a set of coordinates (with a little header
on it).  You can think of it as a long list of X,Y pairs.  Each object
may be represented by 1 pair or by many pairs.  The .shx file is the
index for the .shp file, and it is just a list of pointers into the .shp
file.  The first entry in the .shx file is the index (offset) of the
first coordinate for the first object in the .shp file.  The second
entry in the .shx file is the index of the first coordinate for the
second object in the .shp file.  .shp polygons always close by repeating
the first vertex, so a triangle has four coordinate entries.  If you had
a shapefile with one triangle and one square in it, the .shp file would
have 9 entries in it (4 coordinate pairs for the triangle, 5 for the
square) and the .shx file would have two entries in it - one for each
object.  The first entry in the .shx file would point to coordinate pair
#1 in the .shp file, and the second entry would point to coordinate pair
#5 in the .shp file.  The .dbf file will have the same number of records
as the .shx file, in a one-to-one relationship.  The fifth record in the
.dbf file is the attribute data for the fifth object in the .shx file.
There must be exactly the same number of records in the .shx file and in
the .dbf file.

So - your problem sounds like an extra record got added at the front of
the .dbf file, or one record got deleted at the front of the .shx file,
or something along those lines.  You should use shpdump and dbfdump to
check that there is exactly the same number of records in the .shx and
.dbf files.  Then check on what you know about the source of these
shapefiles.  Some applications are more tolerant of defective shapefiles
than others.  This sounds, however, like a post-creation editing step
causing the problem.  There are many applications that can read/edit
.dbf files as simple database tables, so it is certainly possible for
something to happen to the .dbf file to cause it to get out of sync with
the .shx file.

	- Ed

Ed McNierney
President and Chief Mapmaker
TopoZone.com / Maps a la carte, Inc.
73 Princeton Street, Suite 305
North Chelmsford, MA  01863
Phone: +1 (978) 251-4242
Fax: +1 (978) 251-1396
ed at topozone.com

-----Original Message-----
From: Bart van den Eijnden [mailto:BEN at Syncera-ITSolutions.NL] 
Sent: Tuesday, November 15, 2005 11:09 AM
To: gdal-dev at lists.maptools.org; Ed McNierney
Subject: RE: [Gdal-dev] shifted objects in shapefiles

Hi Ed,

sorry for the confusion, with "shifted" I meant that the shape object of
dbf record X seems to be at position X+1, as an example.

Best regards,
Bart

Bart van den Eijnden
Syncera IT Solutions
Postbus 270
2600 AG  DELFT

tel.nr.: 015-7512436
email: BEN at Syncera-ITSolutions.nl

>>> "Ed McNierney" <ed at topozone.com> 15-11-2005 17:05:38 >>>
Bart -

How do you know they're shifted?  Shapefiles do not store projection
information (it has to be provided externally) and your symptom sounds
(at first glance) to be a projection/datum problem.

You can use shpdump to dump the coordinates of the objects in the
shapefile to examine them manually.  I would first check the projection
info for the shapefile (you can use ogrinfo).

	- Ed

Ed McNierney
President and Chief Mapmaker
TopoZone.com / Maps a la carte, Inc.
73 Princeton Street, Suite 305
North Chelmsford, MA  01863
Phone: +1 (978) 251-4242
Fax: +1 (978) 251-1396
ed at topozone.com 

-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of Bart van den
Eijnden
Sent: Tuesday, November 15, 2005 10:27 AM
To: gdal-dev at lists.maptools.org
Subject: [Gdal-dev] shifted objects in shapefiles

Hi list,

first of all, I am not very familiar with shapefile internals, so please
ignore my possible ignorance .... and ofcourse excuse the fact that this
is a bit off-topic.

We have a problem with shifted geo-objects in shapefiles, the geometry
which is associated with a certain records is the wrong one, so things
are shifted.

Is there any way to restore this? Or are things lost?

Thanks in advance.

Best regards,
Bart

Bart van den Eijnden
Syncera IT Solutions
Postbus 270
2600 AG  DELFT

tel.nr.: 015-7512436
email: BEN at Syncera-ITSolutions.nl 


_______________________________________________
Gdal-dev mailing list
Gdal-dev at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/gdal-dev





More information about the Gdal-dev mailing list