1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Rehashing XML data (Esri Shapefiles to bgl)

Discussion in 'Tools programming' started by Timmo, 17/1/08.

  1. Timmo

    Timmo

    Joined:
    10/1/07
    Messages:
    547
    Country:
    newzealand
    Hi there- A bit of background first. Im a GIS analyst working with ESRI ArcGIS software; the same program Aces used to compile all the data for FSX (Roads, terrain, shorelines etc etc)

    Most of the worlds spatial data is held in GIS formats of varying formats: One of the most commone is the ESRI shapefile format (other formats can be converted in shapefiles without too much hassel). Obviously the SDK does provide some tools for resample of shapefiles (i.e.Shp2Vec.exe) which are great and allow one to convert a wealth of existing data for use in FSX.
    What Shp2Vec doesnt allow, unfortunately, is conversion of a point shapefile into a bgl containing scenery items (i.e. a point dataset could contain locations of Lighthouses with the GUID of that model held in the attribute table). If it did, it would be easy to place, say, all the lighthouses in a country using existing data.

    ArcGIS allows one to export a shapefile as an XML file so im hoping that it would be easy for someone to write a quick script/program re-order the XML into the formatting needed for bglcomp.exe (all the data needed is in the exported XML, it just needs to be reformatted: Lat/long coords, GUUID, Friendlyname, scenery complexity etc etc).

    Alternatively, its possible to export point data as a simple excelspread sheet or dbf file with each row containing information about a scenery object (lat, long, GUID, friendly name etc)

    Coders: How hard is to write this sort of program??

    (Obviously some sort of common formatting standard would need to agreed for the shapefiles unless it is just as easy to search through the XML tags to extract the relevant pieces of info)

    Ill post some sample XML data soon.

    Cheers in advance.
    Last edited: 17/1/08
  2. Timmo

    Timmo

    Joined:
    10/1/07
    Messages:
    547
    Country:
    newzealand
    ...just thinking about it some more, perhaps the easiest, most scaleable way to approach it would be to just settle for using excel tables with a common agreed format. It is easy for non GIS users to then be able to create their own scenery lists/spreadsheets for conversion and its easy to convert point GIS data into an excel spreadsheet. For example:

    Lat Lon alt AltitudeIsAgl pitch bank heading imageComplexity FriendlyName GUID scale

    -38.9345234 78.78373 0 TRUE 0 0 0 Normal Lighthouse.mdl {3F2504E0-4F89-11D3-9A0C-0305E82C3301} 1
    -37.5398234 78.12312 0 TRUE 0 0 0 Normal Lighthouse.mdl {3F2504E0-4F89-11D3-9A0C-0305E82C3301} 1
    -37.8111545 76.66343 0 TRUE 0 0 0 Normal NavBouy.mdl {5F2545D3-1H39-00E3-4B2C-9876L82C2911} 1


    There just needs to be some way to place bulk objects without doing it manually.
    Last edited: 17/1/08
  3. Luis_Sá

    Luis_Sá Resource contributor

    Joined:
    16/9/04
    Messages:
    314
    Country:
    portugal
    Hello Timmo,

    My SBuilder for FS9 was able to import Shape Files elements (lines, polygons, and points). Lines were transformed into VTP lines, polygons into LWM or VTP polygons and points into 3D objects (see the picture). At that time I did not know the ESRI Shape file format and I used an intermediate file - Polish Map (MP) - created by MapEdit (http://www.geopainting.com/en/). So I opened the Shape file into MapEdit (made some editing if necessary) and saved it as a Polish Map. Then I appended this MP files into SBuilder (see the picture). In a single go I could define library objects for, for example, mexican restaurants, lighthouses and so on.

    BGL files containing library objects created by SBuilder205 can be seen in FSX but the code is not "FSX code". But you can export the SBuilder file as TXT project and import it back to SbuilderX. You need, though, to make a simple "Find & Replace" command before importing the project back into SBuilderX in order for the objects to be recognized as FSX.

    But I think you can very easily make a XML file in Excel. Looking to your example of export and to a section of a XML

    Code:
    <!-- air_beaconlightmilglow
      --> 
    - <SceneryObject lat="39.9368286111111" lon="-10.175685" alt="0" altitudeIsAgl="TRUE" pitch="0" bank="0" heading="0" imageComplexity="NORMAL">
      <LibraryObject name="{abd29b45-7f2b-43bb-aba8-6b07bb4d0b67}" scale="1" /> 
      </SceneryObject>
    - <!-- air_beaconlightwater
      --> 
    - <SceneryObject lat="39.97528075" lon="-10.0717081666667" alt="0" altitudeIsAgl="TRUE" pitch="0" bank="0" heading="0" imageComplexity="NORMAL">
      <LibraryObject name="{752f37ae-7a46-434a-a77d-779e3b502790}" scale="1" /> 
      </SceneryObject>
    - <!-- AIR_Fire_Station_Huge
      --> 
    - <SceneryObject lat="39.9313354444444" lon="-10.1254892777778" alt="0" altitudeIsAgl="TRUE" pitch="0" bank="0" heading="0" imageComplexity="NORMAL">
      <LibraryObject name="{ac7ff9e6-f5ce-40c4-8d86-36a4bcfcc913}" scale="1" /> 
      </SceneryObject>
    
    It seems that you could create the XML file very easily from the Excel file using simple text functions. For example you would need to place the friendly name in the first column.

    Kind Regards,

    Luis

    Attached Files:

  4. Timmo

    Timmo

    Joined:
    10/1/07
    Messages:
    547
    Country:
    newzealand
    hmm indeed I could....

    The format can really be anything- I just typed that example.
  5. arno

    arno Administrator Staff Member FSDevConf team Resource contributor

    Joined:
    28/5/04
    Messages:
    21,300
    Country:
    netherlands
    Hi,

    It would be quite easy as well to write a converter from SHP to BGLComp XML. When using the shapelib library that is a piece of cake. The only thing that has to be agreed on is the names of the DBF fields containing information like the GUID, image complexity, etc.
  6. Timmo

    Timmo

    Joined:
    10/1/07
    Messages:
    547
    Country:
    newzealand
    Yep- I think using excel is a better solution in this case as not many people have the tools to edit shapefile data directly. It is simple to export point shapes into an excel file and then this can be manipulated (ie column names etc) and reformatted for the required xml. Really the only need for Arc is the editing of the spatial information.

    Editing column names when in a shapfile isnt easy (its possible to edit the .dbf file associated with the shapefile directly in access etc but this can lead to corrupted data/problems). Editing the attributes is far easier in Excel. Editing the spatial location is far easier in Arc :)

    Horses for courses I guess.
  7. Luis_Sá

    Luis_Sá Resource contributor

    Joined:
    16/9/04
    Messages:
    314
    Country:
    portugal
    Hi Timmo,

    Just to clarify (may be we are talking about the same): I think that, either in Excel or in Winword, you can use "Find & Replace" type commands (either manually or using a macro) that can take the exported file and create a XML file ready to be taken by BGLComp. It depends on how you are familiar with Excel but I would think that Excel is quite good for this task.

    Kind Regards,

    Luis
  8. Timmo

    Timmo

    Joined:
    10/1/07
    Messages:
    547
    Country:
    newzealand
    Hi Luis-

    Yep that is the approach im taking: using the Concatenate command to pick bits from the Raw data (Coordinates, GUUID etc) and a Reference sheet containing all the other 'bits' I need to assemble an XML tag.

    I have run into a problem though: Since every object in the output XML file is more than one row (3 rows including a comment line), but every object in the raw data is only one row I have a one-to-many relationship- I cant seem to make this work in the cell references/formulae so that I can just drag the formula down. I.e. Dragging the formula down will start the reference for the next XML object tag at the Row 5.

    Does anyone know how to set this up so excel ignores the white space between the rows?
    Code:
    <! --radio-->	
    	<SceneryObject lat="-40.3424885347" lon="175.570555192" alt="0" altitudeIsAgl="True" pitch="0" bank="0" heading="0" imageComplexity="Normal">
    	<LibraryObject name ="{79D0AD2B-C7CF-4433-9C7C-25BA72B3327F} "scale="1" />
    <! --obstruction-->	
    	<SceneryObject lat="-40.8488211282" lon="175.570555192" alt="0" altitudeIsAgl="True" pitch="0" bank="0" heading="0" imageComplexity="Normal">
    	<LibraryObject name ="{abd29b45-7f2b-43bb-aba8-6b07bb4d0b67} "scale="1" />
    <! --very high frequency-->	
    
    The formula to get the <!--Radio--> comment is: =CONCATENATE(Reference!$A$12,RawData!A2,Reference!$A$13) where the cell reference to Raw data is only dynamic part.

    If I copy the formula of this cell and paste it in two rows down in order to leave space for the 2 <SceneryObject> Lines, I get: =CONCATENATE(Reference!$A$12,RawData!A5,Reference!$A$13)

    I want this to go to cell A3 on the RawData sheet since this is the next scenery item row which needs to be turned into three rows on the output XML worksheet. It is, of course, updating the reference to A5 since there are two empty cells above (A3, A4) which is including in its count.

    ??
    Last edited: 24/1/08
  9. Luis_Sá

    Luis_Sá Resource contributor

    Joined:
    16/9/04
    Messages:
    314
    Country:
    portugal
    Hello Timmo,

    It looks that you want to transform each row exported by your GIS programme into 3 rows (the 1st row for the friendly name and the 2nd and 3rd for position and other data).

    I think that you can transform one row into one row. I am no expert on XML but I think that your example could be like this:

    Code:
    <! --radio--> <SceneryObject lat="-40.3424885347" lon="175.570555192" alt="0" altitudeIsAgl="True" pitch="0" bank="0" heading="0" imageComplexity="Normal"> <LibraryObject name ="{79D0AD2B-C7CF-4433-9C7C-25BA72B3327F} "scale="1" />
    <! --obstruction-->  <SceneryObject lat="-40.8488211282" lon="175.570555192" alt="0" altitudeIsAgl="True" pitch="0" bank="0" heading="0" imageComplexity="Normal"> <LibraryObject name ="{abd29b45-7f2b-43bb-aba8-6b07bb4d0b67} "scale="1" />
    

    When I was writing this I just opened SBuilderX and created a XML file with 2 objects. In a text editor the file looks like this:

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!--Created by SBuilderX on 25-01-2008 0:50:47-->
    <FSData
      version="9.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="bglcomp.xsd">
      <!--FSX library objects-->
      <!--air_beaconlightwater-->
      <SceneryObject
        lat="39.9533081111111"
        lon="-10.2294661388889"
        alt="0"
        altitudeIsAgl="TRUE"
        pitch="0"
        bank="0"
        heading="0"
        imageComplexity="NORMAL">
        <LibraryObject
          name="{752f37ae-7a46-434a-a77d-779e3b502790}"
          scale="1" />
      </SceneryObject>
      <!--AIR_FBO_LARGE-->
      <SceneryObject
        lat="39.9670410277778"
        lon="-10.1290746944444"
        alt="0"
        altitudeIsAgl="TRUE"
        pitch="0"
        bank="0"
        heading="0"
        imageComplexity="NORMAL">
        <LibraryObject
          name="{c4d3129e-98f4-43c6-a9b9-1954d0f17ec6}"
          scale="1" />
      </SceneryObject>
      <!--FSX Windsock objects-->
      <!--FSX Effect objects-->
      <!--FSX Beacon objects-->
    </FSData>
    So, in this case I have many lines (rows) per object. I am sorry if I did not understand you,

    Luis

Share This Page