[Gvsig_english] How to import a legend file by a python script
Jose Manuel Vivó (Chema)
josemanuel.vivo at iver.es
Thu Mar 29 08:56:25 CEST 2007
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
--
=============
Jose Manuel Vivó (Chema)
Equipo de gvSIG
IVER T.I. S.A.
C/ Salamanca, 50-52
46005-Valencia
Tlf.+34963163400
Spain
www.iver.es
www.gvsig.com
More information about the Gvsig_internacional
mailing list