render map image in scripting

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

render map image in scripting

Andrea Antonello
Hi developers,
I was wondering if there is a possibility to render a map styled map
into an image easily from a script.

Sure, if that was possible (which would be awesome), there would be
the need to also support raster styling and vector labeling. Which is
currently not, right?

Thanks, cheers,
Andrea

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: render map image in scripting

Francisco Puga-2
Hi Andrea,

If you talk about the view and not the layout, i think that there is
an easy, not-pythonic way of doing it. It works like doing a
screenshot show, it will save as a .png file whatever is being shown
in the view. Check this code for inspiration:

# encoding: utf-8

from gvsig import *
from javax.imageio import ImageIO;
from java.io import File


def view_screenshot(output_path, view=currentView()):
    buffered_image = view.getMainWindow().getImage()
    if not output_path.endswith('.png'):
      output_path += '.png'
    output_file = File(output_path)
    ImageIO.write(buffered_image, "png", output_file)


def main(*args):
  view_screenshot('/tmp/foo.png')

Explanation

currentView() returns the "View Document". getMainWindow returns the
window that represents the view, a class that expands from JPanel if i
remember well. And getImage returns a BufferedImage class. So you only
need to use the java utility class ImageIO to "print" it to a file or
an OutputStream.

2016-11-15 17:39 GMT+01:00 andrea antonello <[hidden email]>:

> Hi developers,
> I was wondering if there is a possibility to render a map styled map
> into an image easily from a script.
>
> Sure, if that was possible (which would be awesome), there would be
> the need to also support raster styling and vector labeling. Which is
> currently not, right?
>
> Thanks, cheers,
> Andrea
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel



--
Francisco Puga
iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
http://www.icarto.es/

c/ Rafael Alberti nº 13 – 1º D
15008 A Coruña
Galicia (Spain)
+34 881927808

Este correo electrónico contiene información estrictamente
confidencial y es de uso exclusivo del destinatario, quedando
prohibida a cualquier otra persona su revelación, copia, distribución,
o el ejercicio de cualquier acción relativa a su contenido. Si ha
recibido este mensaje por error, por favor conteste a su remitente
mediante correo electrónico y proceda a borrarlo de su sistema.

Sus datos personales serán tratados de forma confidencial y no serán
cedidos a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer
los derecho de oposición, acceso, rectificación y cancelación de
acuerdo con lo establecido en la Ley Orgánica 15/99, de 13 de
diciembre, de Protección de Datos de Carácter Personal dirigiéndose a
Innovación, Cooperación, Cartografía e Territorio, SL. (ICARTO) en la
dirección postal a C/ Rafael Alberti, nº 13, 1ºD, 15.008 – (A Coruña).

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: render map image in scripting

Andrea Antonello
Hi Francisco,

> If you talk about the view and not the layout, i think that there is
> an easy, not-pythonic way of doing it. It works like doing a
> screenshot show, it will save as a .png file whatever is being shown
> in the view. Check this code for inspiration:

actually, I was hoping for something slightly different.
The code you reference creates a screenshot.

In geotools I have a MapContext, to which I can supply a image size in
pixels, a world envelope, a bunch of layers and a renderer. Then I can
simply create images of certain size based on that configuration.

That way I don't even need a View to be opened.
Is this somehow possible in gvSIG?

Thanks,
Andrea




>
> # encoding: utf-8
>
> from gvsig import *
> from javax.imageio import ImageIO;
> from java.io import File
>
>
> def view_screenshot(output_path, view=currentView()):
>     buffered_image = view.getMainWindow().getImage()
>     if not output_path.endswith('.png'):
>       output_path += '.png'
>     output_file = File(output_path)
>     ImageIO.write(buffered_image, "png", output_file)
>
>
> def main(*args):
>   view_screenshot('/tmp/foo.png')
>
> Explanation
>
> currentView() returns the "View Document". getMainWindow returns the
> window that represents the view, a class that expands from JPanel if i
> remember well. And getImage returns a BufferedImage class. So you only
> need to use the java utility class ImageIO to "print" it to a file or
> an OutputStream.
>
> 2016-11-15 17:39 GMT+01:00 andrea antonello <[hidden email]>:
>> Hi developers,
>> I was wondering if there is a possibility to render a map styled map
>> into an image easily from a script.
>>
>> Sure, if that was possible (which would be awesome), there would be
>> the need to also support raster styling and vector labeling. Which is
>> currently not, right?
>>
>> Thanks, cheers,
>> Andrea
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
>
>
> --
> Francisco Puga
> iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
> http://www.icarto.es/
>
> c/ Rafael Alberti nº 13 – 1º D
> 15008 A Coruña
> Galicia (Spain)
> +34 881927808
>
> Este correo electrónico contiene información estrictamente
> confidencial y es de uso exclusivo del destinatario, quedando
> prohibida a cualquier otra persona su revelación, copia, distribución,
> o el ejercicio de cualquier acción relativa a su contenido. Si ha
> recibido este mensaje por error, por favor conteste a su remitente
> mediante correo electrónico y proceda a borrarlo de su sistema.
>
> Sus datos personales serán tratados de forma confidencial y no serán
> cedidos a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer
> los derecho de oposición, acceso, rectificación y cancelación de
> acuerdo con lo establecido en la Ley Orgánica 15/99, de 13 de
> diciembre, de Protección de Datos de Carácter Personal dirigiéndose a
> Innovación, Cooperación, Cartografía e Territorio, SL. (ICARTO) en la
> dirección postal a C/ Rafael Alberti, nº 13, 1ºD, 15.008 – (A Coruña).
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: render map image in scripting

César Martínez
Hi Anrea, I think you could use the draw or the print methods of
MapContext to produce an image.
You will also need to play with the ViewPort to define the image size.

César

2016-12-05 6:52 GMT+01:00 andrea antonello <[hidden email]>:

> Hi Francisco,
>
>> If you talk about the view and not the layout, i think that there is
>> an easy, not-pythonic way of doing it. It works like doing a
>> screenshot show, it will save as a .png file whatever is being shown
>> in the view. Check this code for inspiration:
>
> actually, I was hoping for something slightly different.
> The code you reference creates a screenshot.
>
> In geotools I have a MapContext, to which I can supply a image size in
> pixels, a world envelope, a bunch of layers and a renderer. Then I can
> simply create images of certain size based on that configuration.
>
> That way I don't even need a View to be opened.
> Is this somehow possible in gvSIG?
>
> Thanks,
> Andrea
>
>
>
>
>>
>> # encoding: utf-8
>>
>> from gvsig import *
>> from javax.imageio import ImageIO;
>> from java.io import File
>>
>>
>> def view_screenshot(output_path, view=currentView()):
>>     buffered_image = view.getMainWindow().getImage()
>>     if not output_path.endswith('.png'):
>>       output_path += '.png'
>>     output_file = File(output_path)
>>     ImageIO.write(buffered_image, "png", output_file)
>>
>>
>> def main(*args):
>>   view_screenshot('/tmp/foo.png')
>>
>> Explanation
>>
>> currentView() returns the "View Document". getMainWindow returns the
>> window that represents the view, a class that expands from JPanel if i
>> remember well. And getImage returns a BufferedImage class. So you only
>> need to use the java utility class ImageIO to "print" it to a file or
>> an OutputStream.
>>
>> 2016-11-15 17:39 GMT+01:00 andrea antonello <[hidden email]>:
>>> Hi developers,
>>> I was wondering if there is a possibility to render a map styled map
>>> into an image easily from a script.
>>>
>>> Sure, if that was possible (which would be awesome), there would be
>>> the need to also support raster styling and vector labeling. Which is
>>> currently not, right?
>>>
>>> Thanks, cheers,
>>> Andrea
>>>
>>> _______________________________________________
>>> gvSIG-desktop-devel mailing list
>>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>
>>
>>
>> --
>> Francisco Puga
>> iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
>> http://www.icarto.es/
>>
>> c/ Rafael Alberti nº 13 – 1º D
>> 15008 A Coruña
>> Galicia (Spain)
>> +34 881927808
>>
>> Este correo electrónico contiene información estrictamente
>> confidencial y es de uso exclusivo del destinatario, quedando
>> prohibida a cualquier otra persona su revelación, copia, distribución,
>> o el ejercicio de cualquier acción relativa a su contenido. Si ha
>> recibido este mensaje por error, por favor conteste a su remitente
>> mediante correo electrónico y proceda a borrarlo de su sistema.
>>
>> Sus datos personales serán tratados de forma confidencial y no serán
>> cedidos a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer
>> los derecho de oposición, acceso, rectificación y cancelación de
>> acuerdo con lo establecido en la Ley Orgánica 15/99, de 13 de
>> diciembre, de Protección de Datos de Carácter Personal dirigiéndose a
>> Innovación, Cooperación, Cartografía e Territorio, SL. (ICARTO) en la
>> dirección postal a C/ Rafael Alberti, nº 13, 1ºD, 15.008 – (A Coruña).
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel



--
SCOLAB
http://scolab.es

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: render map image in scripting

Andrea Antonello
> Hi Anrea, I think you could use the draw or the print methods of
> MapContext to produce an image.
> You will also need to play with the ViewPort to define the image size.

Hmmm, that is interesting. It should give me the possibility to create
data for geopaparazzi using the style of gvSIG (currently it bases on
sld files) and also support all the data types supported in gvSIG
(right now only tiff, asc, and shapefiles).

Do you know off memory if the viewport can be used without a view?
I.e. can I define a mapcontext and viewport and set a CRS on it
without an associated view. Then add layers and be sure they are
correctly reprojected?

Thanks,
Andrea


>
> César
>
> 2016-12-05 6:52 GMT+01:00 andrea antonello <[hidden email]>:
>> Hi Francisco,
>>
>>> If you talk about the view and not the layout, i think that there is
>>> an easy, not-pythonic way of doing it. It works like doing a
>>> screenshot show, it will save as a .png file whatever is being shown
>>> in the view. Check this code for inspiration:
>>
>> actually, I was hoping for something slightly different.
>> The code you reference creates a screenshot.
>>
>> In geotools I have a MapContext, to which I can supply a image size in
>> pixels, a world envelope, a bunch of layers and a renderer. Then I can
>> simply create images of certain size based on that configuration.
>>
>> That way I don't even need a View to be opened.
>> Is this somehow possible in gvSIG?
>>
>> Thanks,
>> Andrea
>>
>>
>>
>>
>>>
>>> # encoding: utf-8
>>>
>>> from gvsig import *
>>> from javax.imageio import ImageIO;
>>> from java.io import File
>>>
>>>
>>> def view_screenshot(output_path, view=currentView()):
>>>     buffered_image = view.getMainWindow().getImage()
>>>     if not output_path.endswith('.png'):
>>>       output_path += '.png'
>>>     output_file = File(output_path)
>>>     ImageIO.write(buffered_image, "png", output_file)
>>>
>>>
>>> def main(*args):
>>>   view_screenshot('/tmp/foo.png')
>>>
>>> Explanation
>>>
>>> currentView() returns the "View Document". getMainWindow returns the
>>> window that represents the view, a class that expands from JPanel if i
>>> remember well. And getImage returns a BufferedImage class. So you only
>>> need to use the java utility class ImageIO to "print" it to a file or
>>> an OutputStream.
>>>
>>> 2016-11-15 17:39 GMT+01:00 andrea antonello <[hidden email]>:
>>>> Hi developers,
>>>> I was wondering if there is a possibility to render a map styled map
>>>> into an image easily from a script.
>>>>
>>>> Sure, if that was possible (which would be awesome), there would be
>>>> the need to also support raster styling and vector labeling. Which is
>>>> currently not, right?
>>>>
>>>> Thanks, cheers,
>>>> Andrea
>>>>
>>>> _______________________________________________
>>>> gvSIG-desktop-devel mailing list
>>>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>>
>>>
>>>
>>> --
>>> Francisco Puga
>>> iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
>>> http://www.icarto.es/
>>>
>>> c/ Rafael Alberti nº 13 – 1º D
>>> 15008 A Coruña
>>> Galicia (Spain)
>>> +34 881927808
>>>
>>> Este correo electrónico contiene información estrictamente
>>> confidencial y es de uso exclusivo del destinatario, quedando
>>> prohibida a cualquier otra persona su revelación, copia, distribución,
>>> o el ejercicio de cualquier acción relativa a su contenido. Si ha
>>> recibido este mensaje por error, por favor conteste a su remitente
>>> mediante correo electrónico y proceda a borrarlo de su sistema.
>>>
>>> Sus datos personales serán tratados de forma confidencial y no serán
>>> cedidos a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer
>>> los derecho de oposición, acceso, rectificación y cancelación de
>>> acuerdo con lo establecido en la Ley Orgánica 15/99, de 13 de
>>> diciembre, de Protección de Datos de Carácter Personal dirigiéndose a
>>> Innovación, Cooperación, Cartografía e Territorio, SL. (ICARTO) en la
>>> dirección postal a C/ Rafael Alberti, nº 13, 1ºD, 15.008 – (A Coruña).
>>>
>>> _______________________________________________
>>> gvSIG-desktop-devel mailing list
>>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
>
>
> --
> SCOLAB
> http://scolab.es
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: render map image in scripting

Joaquin Jose del Cerro Murciano


2016-12-06 10:15 GMT+01:00 andrea antonello <[hidden email]>:
> Hi Anrea, I think you could use the draw or the print methods of
> MapContext to produce an image.
> You will also need to play with the ViewPort to define the image size.

Hmmm, that is interesting. It should give me the possibility to create
data for geopaparazzi using the style of gvSIG (currently it bases on
sld files) and also support all the data types supported in gvSIG
(right now only tiff, asc, and shapefiles).

Do you know off memory if the viewport can be used without a view?



Yes, it can be used without a view.
You can create a MapContext and add the layers you need, with the symbology you need.

Use the MapContextLocator to create the mapcontext, the layers you need, and its symbology.

You can consult:

http://downloads.gvsig.org/download/web/html/es/scripting_devel_guide/2.3/modelo_de_clases_simplificado.html#mapcontext

To see a small diagram, and

http://downloads.gvsig.org/download/web/html/es/scripting_devel_guide/2.3/leyendas.html

To see how to create some legends from scripting.

a greeting
Joaquin

------

Si, se puede usar sin una vista.
Puedes crear un MapContext y añadirle las capas que necesites, con la simbologia que precesis.

Usa el MapContextLocator para crear el mapcontext, las capas que precises, y su simbologia.

Puedes consultar:

http://downloads.gvsig.org/download/web/html/es/scripting_devel_guide/2.3/modelo_de_clases_simplificado.html#mapcontext

Para ver un pequeño diagrama, y

http://downloads.gvsig.org/download/web/html/es/scripting_devel_guide/2.3/leyendas.html

Para ver como crear algunas leyendas desde scripting.

Un saludo
Joaquin



 
I.e. can I define a mapcontext and viewport and set a CRS on it
without an associated view. Then add layers and be sure they are
correctly reprojected?

Thanks,
Andrea


>
> César
>
> 2016-12-05 6:52 GMT+01:00 andrea antonello <[hidden email]>:
>> Hi Francisco,
>>
>>> If you talk about the view and not the layout, i think that there is
>>> an easy, not-pythonic way of doing it. It works like doing a
>>> screenshot show, it will save as a .png file whatever is being shown
>>> in the view. Check this code for inspiration:
>>
>> actually, I was hoping for something slightly different.
>> The code you reference creates a screenshot.
>>
>> In geotools I have a MapContext, to which I can supply a image size in
>> pixels, a world envelope, a bunch of layers and a renderer. Then I can
>> simply create images of certain size based on that configuration.
>>
>> That way I don't even need a View to be opened.
>> Is this somehow possible in gvSIG?
>>
>> Thanks,
>> Andrea
>>
>>
>>
>>
>>>
>>> # encoding: utf-8
>>>
>>> from gvsig import *
>>> from javax.imageio import ImageIO;
>>> from java.io import File
>>>
>>>
>>> def view_screenshot(output_path, view=currentView()):
>>>     buffered_image = view.getMainWindow().getImage()
>>>     if not output_path.endswith('.png'):
>>>       output_path += '.png'
>>>     output_file = File(output_path)
>>>     ImageIO.write(buffered_image, "png", output_file)
>>>
>>>
>>> def main(*args):
>>>   view_screenshot('/tmp/foo.png')
>>>
>>> Explanation
>>>
>>> currentView() returns the "View Document". getMainWindow returns the
>>> window that represents the view, a class that expands from JPanel if i
>>> remember well. And getImage returns a BufferedImage class. So you only
>>> need to use the java utility class ImageIO to "print" it to a file or
>>> an OutputStream.
>>>
>>> 2016-11-15 17:39 GMT+01:00 andrea antonello <[hidden email]>:
>>>> Hi developers,
>>>> I was wondering if there is a possibility to render a map styled map
>>>> into an image easily from a script.
>>>>
>>>> Sure, if that was possible (which would be awesome), there would be
>>>> the need to also support raster styling and vector labeling. Which is
>>>> currently not, right?
>>>>
>>>> Thanks, cheers,
>>>> Andrea
>>>>
>>>> _______________________________________________
>>>> gvSIG-desktop-devel mailing list
>>>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>>
>>>
>>>
>>> --
>>> Francisco Puga
>>> iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
>>> http://www.icarto.es/
>>>
>>> c/ Rafael Alberti nº 13 – 1º D
>>> 15008 A Coruña
>>> Galicia (Spain)
>>> <a value="+34881927808" href="tel:%2B34%20881927808">+34 881927808
>>>
>>> Este correo electrónico contiene información estrictamente
>>> confidencial y es de uso exclusivo del destinatario, quedando
>>> prohibida a cualquier otra persona su revelación, copia, distribución,
>>> o el ejercicio de cualquier acción relativa a su contenido. Si ha
>>> recibido este mensaje por error, por favor conteste a su remitente
>>> mediante correo electrónico y proceda a borrarlo de su sistema.
>>>
>>> Sus datos personales serán tratados de forma confidencial y no serán
>>> cedidos a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer
>>> los derecho de oposición, acceso, rectificación y cancelación de
>>> acuerdo con lo establecido en la Ley Orgánica 15/99, de 13 de
>>> diciembre, de Protección de Datos de Carácter Personal dirigiéndose a
>>> Innovación, Cooperación, Cartografía e Territorio, SL. (ICARTO) en la
>>> dirección postal a C/ Rafael Alberti, nº 13, 1ºD, 15.008 – (A Coruña).
>>>
>>> _______________________________________________
>>> gvSIG-desktop-devel mailing list
>>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
>
>
> --
> SCOLAB
> http://scolab.es
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel



--
--------------------------------------
Joaquin Jose del Cerro Murciano
Development and software arquitecture manager at gvSIG Team
[hidden email]
[hidden email]
gvSIG Association
www.gvsig.com
www.gvsig.org

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel