2

My goal is to create a KML line and/or polygon where the z-values of the vertices equal the z-values from point data (where the csv has a Z field).

So far, I have created a spreadsheet which, given a couple of data inputs, autogenerates a large list of points (X, Y and Z values). The points can be grouped a few different sections (e.g. poly1, poly2 etc with each poly consisting of 20 or so nodes).

I carefully added fields for the purposes of autogenerating lines and or polygons in QGIS using the Points2One plugin.

So, now I have one layer with a couple of shapes (lines or polygons) using the Points2One plug, but it only provides one z value per shape.

I now also have another layer with a z-value for each node.

What I need to do now is incorporate the two layers into a KML, where the coordinates noted in the code also consists of the z-value.

I saved as the polygon or line layer as a KML. Each shape looks something like this in the text editor:

</Schema>
<Folder><name>experiment2</name>
  <Placemark>
                <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
                <ExtendedData><SchemaData schemaUrl="#experiment2">
                                <SimpleData name="Number">13</SimpleData>
                                <SimpleData name="ID">N_A_IHSL2</SimpleData>
                                <SimpleData name="E">379209.579000000030000</SimpleData>
                                <SimpleData name="N">6947509.932000000000000</SimpleData>
                                <SimpleData name="Z">151.000000000000000</SimpleData>
                                <SimpleData name="Dist_Par">-60.000000000000000</SimpleData>
                                <SimpleData name="Dist_Perp">-4000.000000000000000</SimpleData>
                                <SimpleData name="E_Dif">-2635.209433000000000</SimpleData>
                                <SimpleData name="N_Dif">-3009.862329999999900</SimpleData>
                                <SimpleData name="Z_Dif">145.000000000000000</SimpleData>
                                <SimpleData name="RWY">N</SimpleData>
                                <SimpleData name="AppTO">_A_</SimpleData>
                                <SimpleData name="Node">HIS</SimpleData>
                </SchemaData></ExtendedData>
      <LineString><altitudeMode>relativeToGround</altitudeMode><coordinates>
151.83745280810635,-27.583204004361775 
151.82742836624948,-27.592916099990077 
151.83099388901749,-27.537821959903887 
151.77613171577133,-27.590962209266038
</coordinates>
</LineString>
</Placemark>

As you can see, all the coordinates are there for the shape (the x,y) but there is no z.

How do I automatically append the z value in the KML such that each vertex also incorporates the z value?????

5
  • There are 2D, 3D and 4D shape files. When you create one from a csv file with x and y xou get 2D shape. Try the Add delimited text tool with WKT field, where you can define z, too. You can even create the polylines in a WKT field.
    – Zoltan
    Feb 4, 2016 at 6:48
  • Hey thank you for bringing the wkt thing to my attention. It could be useful except I'm not sure how to format the csv properly to get the shapes appearing on screen. At the moment I have each vertex in individual rows. Do I need to put a list of vertices in one row? How would I have the lines connecting m each coordinate and z value drawn up?
    – LHo
    Feb 4, 2016 at 14:36
  • You should put all points in a single cell as a WKT polygon, for exeample: POLYGON ((30 10 11, 40 40 22, 20 40 12, 10 20 18, 30 10 11)). Pay attention to the double brackets. Unfortunately the Z coordinate is dropped in QGIS 2.8 where I tested it. :(. So it won't help you. Sorry for the noise.
    – Zoltan
    Feb 4, 2016 at 17:16
  • I did a bit of research and a play with it. I never got it working and I have QGIS 2.12.3. I'll have a bit more of a play with this and see if I get it working. However I suspect that it won't solve my problem of auto populating the kml z value for use in google earth. Unless, I create the text using a method similar to auto-creating the wkt fields and then copy paste that text into the kml coordinates section.
    – LHo
    Feb 4, 2016 at 21:50
  • You may also try ogr2ogr, see gis.stackexchange.com/questions/24947/…
    – Zoltan
    Feb 4, 2016 at 22:30

1 Answer 1

1

I've come up with a workflow that works for me.

  1. Create UTM coordinates in Excel with x, y and z values.
  2. Save as this Excel sheet as CSV.
  3. Import the CSV into QGIS.
  4. Reproject the CSV from UTM into WGS84 (lats and longs).
  5. In the reprojected layer, add coordinates values to the attribute table.
  6. Save as the reprojected layer with the added coordinate values in the attribute table into a CSV.
  7. Open the newly created CSV, delete all columns except for the lats, longs and Z values.
  8. Copy and paste the three columns into a KML text editor between the tags and load the KML into Google Earth.

I feel like there is a much quicker and more elegant way of doing it but it does the job.

Thank you all for your responses!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.