Problem importing shp file

General discussion about Scenery Design. Questions about SBuilder for Flight Simulator FS2004.
Post Reply
sinelnic
Posts: 2
Joined: Wed Dec 12, 2007 4:47 am
Location: Argentina

Problem importing shp file

Post by sinelnic » Wed Dec 12, 2007 4:53 am

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!!!

User avatar
Luis Sa
Posts: 1736
Joined: Sun May 18, 2003 11:17 am
Location: Portugal
Contact:

Post by Luis Sa » Wed Dec 12, 2007 10:50 pm

Hello


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
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

User avatar
Luis Sa
Posts: 1736
Joined: Sun May 18, 2003 11:17 am
Location: Portugal
Contact:

Post by Luis Sa » Wed Dec 12, 2007 10:58 pm

Hi again,

Well, reading your projection file it says that your shape file is UTM!!! Therefore you need to convert it to Geographic Lat/Lon!

I tried to open it in a GIS programme and I was successful. But it is in UTM coordinates!!!

Regards, Luis

sinelnic
Posts: 2
Joined: Wed Dec 12, 2007 4:47 am
Location: Argentina

Post by sinelnic » Thu Dec 13, 2007 2:44 pm

Hi Luis,

It worked!! I had already read about projections in other forums but got so messed up investigating the cause of the problem that I didn't quite try the correct reprojection.

Muito Obrigado!

Post Reply