[Gvsig_english] How to import a legend file by a python script

Antonio Falciano afalciano at yahoo.it
Tue Mar 27 17:19:29 CEST 2007


Hi Chema, hi list!
Thanks for your prompt reply! I really appreciate your advices.
I've tested your code in Jython shell and this is the output:

 >>> from java.io import InputStreamReader, FileInputStream, File
 >>> from com.iver.utiles.xmlEntity.generate import XmlTag
 >>> 
LegendFactory=gvSIG.classForName("com.iver.cit.gvsig.fmap.rendering.LegendFactory")
 >>> pathToFile="D:\workspace\myLegend.gvl"
 >>> myReader=InputStreamReader(FileInputStream(File(pathToFile)),"UTF-8")
 >>> myXML=XmlTag.unmarshal(myReader)
 >>> LegendFactory.createFromXML(myXML)
TypeError: createFromXML(): 1st arg can't be coerced to 
com.iver.utiles.XMLEntity

It seems that the latest command line don't work properly.
Why cannot "myXML" (1st arg?) be coerced/passed to createFromXML?
Is there a limitation of characters in XmlTag?

Best regards,
Antonio


Jose Manuel Vivó (Chema) wrote:
> Hi Antonio:
>
> The method 'VectorialUniqueValueLegend' recive an instance of 
> 'XMLEntity' (com.iver.utiles.XMLEntity) and not a string.
>
> Normally this kind of errors prints a trace in the java console.
>
>
> You can try to load a legend from a file using this function:
>
> def loadLeyendFromFile(pathToFile):
>   # imports 
>   from java.io import InputStreamReader, FileInputStream, File
>
>   from com.iver.utiles.xmlEntity.generate import XmlTag
>
>   LegendFactory = 
> gvSIG.classForName("com.iver.cit.gvsig.fmap.rendering.LegendFactory")
>
>   # code
>   reader = InputStreamReader( FileInputStream(File(pathToFile)),"UTF-8")
>
>   xml = XmlTag.unmarshal(reader)
>
>   return LegendFactory.createFromXML(xml)
>
>
>
> Good Luck
>
> Chema.
>
>
> El Sábado 24 Marzo 2007 13:17, Antonio Falciano escribió:
>   
>> Hi list,
>>  I'm trying to import a legend file and then assign to a vectorial layer by
>> a python script:
>>
>>      [cut]
>>
>>      # Add theme to the mapContext layer list of the view
>>      mapContext.getLayers().addLayer(myLayer)
>>     
>>      # Set theme legend file
>>     
>> myLegendFileName=os.path.join(gvSIG.getScriptsDirectory(),"..","..","myExte
>> nsion","myLegendFile.gvl")
>> myLegend=gvSIG.classForName("com.iver.cit.gvsig.fmap.rendering.VectorialUni
>> queValueLegend") myLegend.setXMLEntity(myLegendFileName)
>>      myLayer.setLegend(myLegend)
>>      #myLayer.setXMLEntity(myLegendFileName)
>>         
>>      # Refresh the mapContext
>>      mapContext.invalidate()
>>
>>  ...but I obtain only my layer with a default single symbol legend. Where
>> am I wrong? I'm using gvSIG 1.0.1 with both JCRS and Piloto Raster
>> extensions not active.
>>
>>  Best regards,
>>  Antonio Falciano
>>  freelancer engineer
>>  intern at Regional Rivers Authority of Basilicata, Italy
>>     
>
>   




More information about the Gvsig_internacional mailing list