Select to view content in your preferred language

KMZ to KmlDocument

459
2
Jump to solution
06-10-2022 08:56 AM
AngeloSilva
Emerging Contributor

I would like to know if there is how to load a kmz file, and then, to generate a kmldocument from this kmz file.

0 Kudos
1 Solution

Accepted Solutions
PriyankaRupani
Esri Contributor

Hello,

I believe you could be able to do this.

sample code:

// load a KML dataset from a local KMZ file and show it as an operational layer
KmlDataset kmlDataset = new KmlDataset(kmz_data_path);
KmlLayer kmlLayer = new KmlLayer(kmlDataset);
SceneView.getScene().getOperationalLayers().add(kmlLayer);

// listen for the KML dataset to finish loading
// generate a kmldocument from this kmz file
kmlDataset.addDoneLoadingListener(() -> {
if (kmlDataset.getLoadStatus() == LoadStatus.LOADED) {
List<KmlNode> nodes = mKmlDataset.getRootNodes();
KmlNode rootNode = nodes.get(0);
assertTrue("Expected the root node to be a KmlDocument", (rootNode instanceof KmlDocument));
KmlDocument kmlDocument = (KmlDocument)rootNode;
}

The sample assumes the root node in the KMZ is a KMLDocument node. 

View solution in original post

0 Kudos
2 Replies
PriyankaRupani
Esri Contributor

Hello,

I believe you could be able to do this.

sample code:

// load a KML dataset from a local KMZ file and show it as an operational layer
KmlDataset kmlDataset = new KmlDataset(kmz_data_path);
KmlLayer kmlLayer = new KmlLayer(kmlDataset);
SceneView.getScene().getOperationalLayers().add(kmlLayer);

// listen for the KML dataset to finish loading
// generate a kmldocument from this kmz file
kmlDataset.addDoneLoadingListener(() -> {
if (kmlDataset.getLoadStatus() == LoadStatus.LOADED) {
List<KmlNode> nodes = mKmlDataset.getRootNodes();
KmlNode rootNode = nodes.get(0);
assertTrue("Expected the root node to be a KmlDocument", (rootNode instanceof KmlDocument));
KmlDocument kmlDocument = (KmlDocument)rootNode;
}

The sample assumes the root node in the KMZ is a KMLDocument node. 

0 Kudos
AngeloSilva
Emerging Contributor

This suggestion works!!!

0 Kudos