[Gvsig_english] How to import a legend file by a python script
Antonio Falciano
afalciano at yahoo.it
Thu Mar 29 22:56:29 CEST 2007
Hi Chema,
thanks a lot! Now it works very good, congratulations.
A function like this would be implemented by default in gvSIG,
so it would be possible to add a layer with its legend just like
in other GIS client.
Regards,
Antonio
Jose Manuel Vivó (Chema) wrote:
> Hi Antonio:
>
> I'm sorry, I forgot one line. Here you have the function one more time:
>
> def loadLeyendFromFile(pathToFile):
> # imports
> from java.io import InputStreamReader, FileInputStream, File
>
> from com.iver.utiles.xmlEntity.generate import XmlTag
> from com.iver.utiles import XMLEntity
>
> LegendFactory =
> gvSIG.classForName("com.iver.cit.gvsig.fmap.rendering.LegendFactory")
>
> # code
> reader = InputStreamReader( FileInputStream(File(pathToFile)),"UTF-8")
>
> xml = XMLEntity(XmlTag.unmarshal(reader))
>
> return LegendFactory.createFromXML(xml)
>
> Regards
> Chema.
>
> El Martes 27 Marzo 2007 17:19, Antonio Falciano escribió:
>
>> 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.LegendF
>> actory")
>>
>> >>> 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(),"..","..","myE
>>>> xte nsion","myLegendFile.gvl")
>>>> myLegend=gvSIG.classForName("com.iver.cit.gvsig.fmap.rendering.Vectorial
>>>> Uni 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
>>>>
>> _______________________________________________
>> Gvsig_internacional mailing list
>> Gvsig_internacional at runas.cap.gva.es
>> http://runas.cap.gva.es/mailman/listinfo/gvsig_internacional
>>
>
>
More information about the Gvsig_internacional
mailing list