create raster layer

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

create raster layer

Andrea Antonello
Hi, I am trying to upgrade my plugins for gvSIG 2.4.

Since some things have changed in the raster part, I assume that is
the reason for my problems.

I used to create a new raster layer programmatically through:

        MapContext mapContext = ProjectUtilities.getCurrentMapcontext();
        if (mapContext != null) {
            ProviderServices provServ =
RasterLocator.getManager().getProviderServices();
            RasterDataParameters storeParameters =
provServ.createParameters(rasterFile.getName());
            storeParameters.setURI(rasterFile.toURI());

            MapContextManager mcm = MapContextLocator.getMapContextManager();
            DefaultFLyrRaster rasterLayer = (DefaultFLyrRaster)
mcm.createLayer(layerName, storeParameters);

            mapContext.getLayers().addLayer(rasterLayer);
        }


But now I get a NPE in the createParameters method:

public RasterDataParameters createParameters(String id) {
Iterator<?> it =
DALFileLocator.getFilesystemServerExplorerManager().getRegisteredProviders();
while (it.hasNext()) {
ExtensionPoint.Extension o = (ExtensionPoint.Extension)it.next();
Class<?> c = o.getExtension();
[...]

Basically the 'c' is NULL when it tries to get the Extension (from a
DGN Extension Point, while my file is a TIFF).


How am I supposed to create a new raster layer in 2.4?

Thanks,
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: create raster layer

Joaquin Jose del Cerro Murciano


2017-02-20 11:14 GMT+01:00 andrea antonello <[hidden email]>:
Hi, I am trying to upgrade my plugins for gvSIG 2.4.

Since some things have changed in the raster part, I assume that is
the reason for my problems.

I used to create a new raster layer programmatically through:

        MapContext mapContext = ProjectUtilities.getCurrentMapcontext();
        if (mapContext != null) {
            ProviderServices provServ =
RasterLocator.getManager().getProviderServices();
            RasterDataParameters storeParameters =
provServ.createParameters(rasterFile.getName());
            storeParameters.setURI(rasterFile.toURI());

            MapContextManager mcm = MapContextLocator.getMapContextManager();
            DefaultFLyrRaster rasterLayer = (DefaultFLyrRaster)
mcm.createLayer(layerName, storeParameters);

            mapContext.getLayers().addLayer(rasterLayer);
        }


But now I get a NPE in the createParameters method:

public RasterDataParameters createParameters(String id) {
Iterator<?> it =
DALFileLocator.getFilesystemServerExplorerManager().getRegisteredProviders();
while (it.hasNext()) {
ExtensionPoint.Extension o = (ExtensionPoint.Extension)it.next();
Class<?> c = o.getExtension();
[...]

Basically the 'c' is NULL when it tries to get the Extension (from a
DGN Extension Point, while my file is a TIFF).


How am I supposed to create a new raster layer in 2.4?

At the moment there is still no build of the 2.4, so I do not recommend that you use it.
I have not even finished compiling all the plugins for that version.

Anyway, how to create the layer you use is not correct.
Surely you will have dependencies in your project (pom) that you should not have.

When I finish doing the build and try to create a raster layer by code and I comment as it would be.

a greeting
Joaquin

 
Thanks,
Andrea

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: create raster layer

Andrea Antonello
Hi Joaquin,

> At the moment there is still no build of the 2.4, so I do not recommend that
> you use it.
> I have not even finished compiling all the plugins for that version.

you are right. After writing the email I noticed it and tried to
figure out what could have happened. I think there has been some mixup
of different compilations of gvSIG and they ended up in the 2.3
installation.

I now cleaned up everything.

> Anyway, how to create the layer you use is not correct.
> Surely you will have dependencies in your project (pom) that you should not
> have.
>
> When I finish doing the build and try to create a raster layer by code and I
> comment as it would be.


ok, thanks.

regarding the 2.3 version? Is the way of creating a raster layer also wrong?


Cheers,
Andrea


>
> a greeting
> Joaquin
>
>
>>
>> Thanks,
>> Andrea
>>
>> _______________________________________________
>> 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

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

Re: create raster layer

Joaquin Jose del Cerro Murciano


2017-02-20 12:54 GMT+01:00 andrea antonello <[hidden email]>:
Hi Joaquin,

> At the moment there is still no build of the 2.4, so I do not recommend that
> you use it.
> I have not even finished compiling all the plugins for that version.

you are right. After writing the email I noticed it and tried to
figure out what could have happened. I think there has been some mixup
of different compilations of gvSIG and they ended up in the 2.3
installation.

I now cleaned up everything.

> Anyway, how to create the layer you use is not correct.
> Surely you will have dependencies in your project (pom) that you should not
> have.
>
> When I finish doing the build and try to create a raster layer by code and I
> comment as it would be.


ok, thanks.

regarding the 2.3 version? Is the way of creating a raster layer also wrong?



Hello Andrea,
To create the raster store, you are using ProviderServices, which
is at SPI. You are also accessing RasterDataParameters,
which are in raster implementation.

The correct thing would be to use the DataManager (API of DAL) to
create the parameters for opening the store, fill them, and then
open the store.

      DataParameters parameters = dataManager.createStoreParameters("Gdal Store");
      parameters.setDynValue("uri", rasterFile.toURI());
      DataStore store = dataManager.openStore("Gdal Store", parameters);

This use only API, no implementation no SPI.
This form should work in both gvSIG 2.2, 2.3, 2.4 and later.
And is similar to how the vector layers are created.

In gvSIG 2.5 will change all raster; But this should continue to work.
The only thing to change is the name of the raster provider.
In 2.5, instead of using "Gdal Store" as raster provider name, we will
have to use "GTiff", "png", "jpg" ... one per format. "Gdal Store" will
be deprecated, but can be used for a few versions.

A script that use this as an explample (in groovy ;) ):

//------><--------><----------><--------------

import java.io.File;

import org.gvsig.app.ApplicationLocator;
import org.gvsig.app.ApplicationManager;
import org.gvsig.app.project.documents.view.ViewDocument;
import org.gvsig.app.project.documents.view.ViewManager;
import org.gvsig.fmap.dal.DALLocator;
import org.gvsig.fmap.dal.DataManager;
import org.gvsig.fmap.dal.DataParameters;
import org.gvsig.fmap.dal.DataStore;
import org.gvsig.fmap.mapcontext.MapContext;
import org.gvsig.fmap.mapcontext.MapContextLocator;
import org.gvsig.fmap.mapcontext.MapContextManager;
import org.gvsig.fmap.mapcontext.layers.FLayer;

def main() {

  ApplicationManager application = ApplicationLocator.getManager();

  File[] files = application.showOpenFileDialog(
    "Select a raster file",
    new File(System.getProperty("user.home"))
  );
  if( files == null || files.length<1 ) {
    application.messageDialog("Must select a raster file","Warning",0);
    return;
  }
  File rasterFile = files[0]
 
  ViewDocument view = (ViewDocument) application.getActiveDocument(
    ViewManager.TYPENAME
  );
  if( view == null ) {
    application.messageDialog("There must be an active view.","Warning",0);
    return;
  }
  MapContext mapContext = view.getMapContext();
  if (mapContext != null) {
      // Create the DataManager
      DataManager dataManager = DALLocator.getDataManager();
      // Create the store parameters that we need to load the raster from the DataManager
      DataParameters parameters = dataManager.createStoreParameters("Gdal Store");
      // Fill the parameters
      parameters.setDynValue("uri", rasterFile.toURI());
      // Open the store with the parameters from the DataManager
      DataStore store = dataManager.openStore("Gdal Store", parameters);

      // Make a layer name based on the raster file
      String layerName = store.getName();

      // Create the raster layer from the MapContextManageer
      MapContextManager mcm = MapContextLocator.getMapContextManager();
      FLayer rasterLayer = mcm.createLayer(layerName, store);

      // Add the raster layer to the MapContext of the view
      mapContext.getLayers().addLayer(rasterLayer);
  }

}
//------><--------><----------><--------------


Saludos
Joaquin


 
Cheers,
Andrea


>
> a greeting
> Joaquin
>
>
>>
>> Thanks,
>> Andrea
>>
>> _______________________________________________
>> 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

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: create raster layer

Andrea Antonello
Hi Joaquin,

> Hello Andrea,
> To create the raster store, you are using ProviderServices, which
> is at SPI. You are also accessing RasterDataParameters,
> which are in raster implementation.
>
> The correct thing would be to use the DataManager (API of DAL) to
> create the parameters for opening the store, fill them, and then
> open the store.
>
>       DataParameters parameters = dataManager.createStoreParameters("Gdal
> Store");
>       parameters.setDynValue("uri", rasterFile.toURI());
>       DataStore store = dataManager.openStore("Gdal Store", parameters);
>
> This use only API, no implementation no SPI.
> This form should work in both gvSIG 2.2, 2.3, 2.4 and later.
> And is similar to how the vector layers are created.
>
> In gvSIG 2.5 will change all raster; But this should continue to work.
> The only thing to change is the name of the raster provider.
> In 2.5, instead of using "Gdal Store" as raster provider name, we will
> have to use "GTiff", "png", "jpg" ... one per format. "Gdal Store" will
> be deprecated, but can be used for a few versions.

thanks a lot for the explanation.


>
> A script that use this as an explample (in groovy ;) ):


Ha ha ha, genial, thanks!!


Ciao,
Andrea




>
> //------><--------><----------><--------------
>
> import java.io.File;
>
> import org.gvsig.app.ApplicationLocator;
> import org.gvsig.app.ApplicationManager;
> import org.gvsig.app.project.documents.view.ViewDocument;
> import org.gvsig.app.project.documents.view.ViewManager;
> import org.gvsig.fmap.dal.DALLocator;
> import org.gvsig.fmap.dal.DataManager;
> import org.gvsig.fmap.dal.DataParameters;
> import org.gvsig.fmap.dal.DataStore;
> import org.gvsig.fmap.mapcontext.MapContext;
> import org.gvsig.fmap.mapcontext.MapContextLocator;
> import org.gvsig.fmap.mapcontext.MapContextManager;
> import org.gvsig.fmap.mapcontext.layers.FLayer;
>
> def main() {
>
>   ApplicationManager application = ApplicationLocator.getManager();
>
>   File[] files = application.showOpenFileDialog(
>     "Select a raster file",
>     new File(System.getProperty("user.home"))
>   );
>   if( files == null || files.length<1 ) {
>     application.messageDialog("Must select a raster file","Warning",0);
>     return;
>   }
>   File rasterFile = files[0]
>
>   ViewDocument view = (ViewDocument) application.getActiveDocument(
>     ViewManager.TYPENAME
>   );
>   if( view == null ) {
>     application.messageDialog("There must be an active view.","Warning",0);
>     return;
>   }
>   MapContext mapContext = view.getMapContext();
>   if (mapContext != null) {
>       // Create the DataManager
>       DataManager dataManager = DALLocator.getDataManager();
>       // Create the store parameters that we need to load the raster from
> the DataManager
>       DataParameters parameters = dataManager.createStoreParameters("Gdal
> Store");
>       // Fill the parameters
>       parameters.setDynValue("uri", rasterFile.toURI());
>       // Open the store with the parameters from the DataManager
>       DataStore store = dataManager.openStore("Gdal Store", parameters);
>
>       // Make a layer name based on the raster file
>       String layerName = store.getName();
>
>       // Create the raster layer from the MapContextManageer
>       MapContextManager mcm = MapContextLocator.getMapContextManager();
>       FLayer rasterLayer = mcm.createLayer(layerName, store);
>
>       // Add the raster layer to the MapContext of the view
>       mapContext.getLayers().addLayer(rasterLayer);
>   }
>
> }
> //------><--------><----------><--------------
>
>
> Saludos
> Joaquin
>
>
>
>>
>> Cheers,
>> Andrea
>>
>>
>> >
>> > a greeting
>> > Joaquin
>> >
>> >
>> >>
>> >> Thanks,
>> >> Andrea
>> >>
>> >> _______________________________________________
>> >> 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
>>
>> _______________________________________________
>> 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

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