Hi,
First of all thanks for this great and free product!!
I'm having problems importing a particular shapefile into SBuilderX. I get the message "SBuilder cannot read this shapefile!", and can't figure out why.
I could import other shapefiles, e.g. the samples from the SDK, or shp that I exported from SBuilder. The file I'm trying to import has "polygon" type of shape, instead of the "PolygonZ" type of shape the other, succesfully imported .shp files have. Also, my file includes a .prj for projection information.
The file can be accessed in http://caece.edu.ar/tea/images/Lagos.zip
Thanks for the help!!!
Problem importing shp file
Hello
Here is the the code to asppend shape files:
I have removed the coments on the the debug.print statements and I got these values:
5
257355.8125
319421.6875
5443994.8125
5627299.6875
True
which means that your file is really a polygon file and that IsValid=True but turns to false because of the bounding boxes values!!!
I hope this gives you some tips on the problems of your shape file. Can you read it with some other programme?
Regards,
Luis
Here is the the code to asppend shape files:
Code: Select all
Friend Sub AppendSHPFile(ByVal filename As String)
Dim hShp As Integer
Dim shpType As Integer
Dim shpObj As SHPObject
Dim pShpObj As IntPtr
Dim IsValid As Boolean = False
Dim IsLine As Boolean = False
IsZ = False
' open shapefile
hShp = SHPOpen(filename, "rb")
' get shape info
Dim NoOfItems As Integer = 0
Dim minBox(3) As Double ' these are 4-element arrays of bounds in the X, Y, Z, and M dimensions
Dim maxBox(3) As Double
Dim pmin As IntPtr = Marshal.AllocHGlobal(32)
Dim pmax As IntPtr = Marshal.AllocHGlobal(32)
' SHPGetInfo expects pointers to double arrays
Call SHPGetInfo(hShp, NoOfItems, shpType, pmin, pmax)
Marshal.Copy(pmin, minBox, 0, 4)
Marshal.Copy(pmax, maxBox, 0, 4)
Marshal.FreeHGlobal(pmin)
Marshal.FreeHGlobal(pmax)
' just in case the header gives a null! if so read first shape
If shpType = 0 Then
pShpObj = SHPReadObject(hShp, 0)
shpObj = Marshal.PtrToStructure(pShpObj, GetType(SHPObject))
shpType = shpObj.nSHPType
maxBox(0) = shpObj.dfXMax
minBox(0) = shpObj.dfXMin
maxBox(1) = shpObj.dfYMax
minBox(1) = shpObj.dfYMin
SHPDestroyObject(pShpObj)
End If
SHPClose(hShp)
If shpType = SHPT_ARC Then
IsValid = True
IsZ = False
IsLine = True
End If
If shpType = SHPT_POLYGON Then
IsValid = True
IsZ = False
IsLine = False
End If
If shpType = SHPT_ARCZ Then
IsValid = True
IsZ = True
IsLine = True
End If
If shpType = SHPT_POLYGONZ Then
IsValid = True
IsZ = True
IsLine = False
End If
'Debug.Print(shpType)
'Debug.Print(minBox(0))
'Debug.Print(maxBox(0))
'Debug.Print(minBox(1))
'Debug.Print(maxBox(1))
'Debug.Print(IsValid)
If minBox(0) < -180 Then IsValid = False
If maxBox(0) > 180 Then IsValid = False
If minBox(1) < -90 Then IsValid = False
If maxBox(1) > 90 Then IsValid = False
If Not IsValid Then GoTo erro1
If IsLine Then
AppendSHPLines(filename, NoOfItems, IsZ)
Else
AppendSHPPolys(filename, NoOfItems, IsZ)
End If
LonDispCenter = (minBox(0) + maxBox(0)) / 2
LatDispCenter = (minBox(1) + maxBox(1)) / 2
ViewON = True
Zoom = 8
ResetZoom()
SetDispCenter(0, 0)
Dirty = True
RebuildDisplay()
Exit Sub
erro1:
MsgBox("SBuilder can not read this Shapefile!", MsgBoxStyle.Exclamation)
End Sub
5
257355.8125
319421.6875
5443994.8125
5627299.6875
True
which means that your file is really a polygon file and that IsValid=True but turns to false because of the bounding boxes values!!!
I hope this gives you some tips on the problems of your shape file. Can you read it with some other programme?
Regards,
Luis