zhikrullah / pyshp

Automatically exported from code.google.com/p/pyshp
MIT License
0 stars 0 forks source link

Polygon Shapes nott readable by ESRI-ArcView3 #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Polygon Shapefile produced with pyshp are not readable with ArcView 3.x
2.
3.

What is the expected output? What do you see instead?
There seems to be a correct Shapefile, but opening in ArcView causes a crash.

What version of the product are you using? On what operating system?
pyshp 1.1.7, python 2.7.3, winXP

Please provide any additional information below.
Solution: the calculation of parts in function poly seems to be misplaced.
    def poly(self, parts=[], shapeType=POLYGON, partTypes=[]):
        """Creates a shape that has multiple collections of points (parts)
        including lines, polygons, and even multipoint shapes. If no shape type
        is specified it defaults to 'polygon'. If no part types are specified
        (which they normally won't be) then all parts default to the shape type.
        """
        polyShape = _Shape(shapeType)
        polyShape.parts = []
        polyShape.points = []
        for part in parts:
            # corrected place of parts calculation (before points are added!
            polyShape.parts.append(len(polyShape.points)) 
            # Make sure polygon is closed
            if shapeType in (5,15,25,31) and part[0] != part[-1]:
                part.append(part[0])
            for point in part:
                # Ensure point is list
                if not isinstance(point, list):
                    point = list(point)
                # Make sure point has z and m values
                while len(point) < 4:
                    point.append(0)
                polyShape.points.append(point)
            #Original place of parts calculation
            #polyShape.parts.append(len(polyShape.points))
        if polyShape.shapeType == 31:
            if not partTypes:
                for part in parts:
                    partTypes.append(polyShape.shapeType)
            polyShape.partTypes = partTypes
        self._shapes.append(polyShape)

Original issue reported on code.google.com by franksco...@yahoo.de on 8 Aug 2013 at 9:03

GoogleCodeExporter commented 8 years ago
Please upgrade to PyShp version 1.1.9 and verify that this issue has been fixed 
as part of several different patches.

Original comment by geospati...@gmail.com on 8 Aug 2013 at 2:59

GoogleCodeExporter commented 8 years ago
Thanks for the amazing fast response. Polygons now are correct.

Original comment by franksco...@yahoo.de on 9 Aug 2013 at 11:37