Solved

Dynamic Writer to Write as KML not KMZ


Badge +1
  • Participant
  • 126 replies

I have a KML writer with dynamic attribute definition. The writer always writes a KMZ file but I want it to write a KML file. When you use a static writer you can specify the filename and extension in the writer as either ".kml" or ".kmz" but when it is dynamic you just give the path to the folder and "fme_feature_type" as the feature type name. Also there is no suffix on which to fan out.

How can I get the writer to write KML?

Thanks

icon

Best answer by takashi 3 May 2017, 05:20

View original

6 replies

Badge +16

Hi @jimo,

I have just created a dynamic translation to KML and I can still change the extension kml to kmz and it works just fine. Try it yourself and change the D: esult2.kmz to D: esult2.kml

acad2ogckml.fmwt

Badge +1

Hi @jimo,

I have just created a dynamic translation to KML and I can still change the extension kml to kmz and it works just fine. Try it yourself and change the D: esult2.kmz to D: esult2.kml

acad2ogckml.fmwt

This works because you are writing the file name. However, in my case the file name will be set by a parameter. When I do it this way, I always get "doc.kml", not the filename that I passed in.

 

 

At any rate, I realized that I can use the zipfile module in the Python shutdown script to extract the doc.kml from the KMZ file, like this:

 

 

import zipfile

 

zip_ref = zipfile.ZipFile(pathToSourceKML, 'r')

 

# Where I want to write the KML

 

zip_ref.extractall(pathToUnzippedKML)

 

zip_ref.close()

 

 

Then I can use shutil.move(src,dst) to change the file name from doc.kml to the name that I want it to be.

 

Badge +16

Also when fetching the parameter value and adding the .kml to it ?

Userlevel 2
Badge +17

Hi @jimo, I think you can control the destination format (KML or KMZ) via file extension (.kml or .kmz) in the string expression for the Fanout Dataset option in the KML writer. e.g. assume that a feature attribute called "_basename" stores the destination filename without extension,

Userlevel 2
Badge +17

Hi @jimo, I think you can control the destination format (KML or KMZ) via file extension (.kml or .kmz) in the string expression for the Fanout Dataset option in the KML writer. e.g. assume that a feature attribute called "_basename" stores the destination filename without extension,

0684Q00000ArKHUQA3.png

If the destination filename without extension will be specified through a user parameter (e.g. named "BASENAME"), this expression is available.

 

$(BASENAME).kml 
Badge +1

Hi @jimo, I think you can control the destination format (KML or KMZ) via file extension (.kml or .kmz) in the string expression for the Fanout Dataset option in the KML writer. e.g. assume that a feature attribute called "_basename" stores the destination filename without extension,

The $(BASENAME).kml is the syntax that works. Thanks @takashi@takashi.

Reply