[Geoserver-users] REST API importer: specify table to load data

Hi to all
I want with geoserver REST API put a shapefile into an existing postgis table.
I know how to load a shapefile into a postgis database, but I don’t know how I could indicate a specific table in which append data.
I Have a shapefile named tableA.shp; it’s possible put it’s data into a postgis table named tableB?
Thanks a lot

Giuseppe

I’m not sure that you need to involve geoserver in this, Ogr2ogr would be quicker and easier to append a shapefile to a database. The GeoServer rest api is for creating data stores and layers etc not individual data management.

Alternatively you might be able to use the importer extension to do this but I’ve not used that in anger

Ian

On Mon, 9 May 2022, 17:25 Giuseppe Falcone, <falcone.giuseppe@anonymised.com> wrote:

Hi to all
I want with geoserver REST API put a shapefile into an existing postgis table.
I know how to load a shapefile into a postgis database, but I don’t know how I could indicate a specific table in which append data.
I Have a shapefile named tableA.shp; it’s possible put it’s data into a postgis table named tableB?
Thanks a lot

Giuseppe


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Hi
thanks for the response.
I’m building a web application that must have this function.
From browser user upload a shapefile e I put into a db table.
I think REST API are perfect for this purpose.

Giuseppe

Il giorno lun 9 mag 2022 alle ore 19:22 Ian Turton <ijturton@anonymised.com> ha scritto:

I’m not sure that you need to involve geoserver in this, Ogr2ogr would be quicker and easier to append a shapefile to a database. The GeoServer rest api is for creating data stores and layers etc not individual data management.

Alternatively you might be able to use the importer extension to do this but I’ve not used that in anger

Ian

On Mon, 9 May 2022, 17:25 Giuseppe Falcone, <falcone.giuseppe@anonymised.com…> wrote:

Hi to all
I want with geoserver REST API put a shapefile into an existing postgis table.
I know how to load a shapefile into a postgis database, but I don’t know how I could indicate a specific table in which append data.
I Have a shapefile named tableA.shp; it’s possible put it’s data into a postgis table named tableB?
Thanks a lot

Giuseppe


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

You may also consider using the resource rest api to upload the file, and the the importer rest api in ingest (it offers greater control as Ian suggests).

The upload you found determines a unique table name based on the provided content, so for your shapefile this is based on the filename.

The file is here https://github.com/geoserver/geoserver/blob/main/src/restconfig/src/main/java/org/geoserver/rest/catalog/DataStoreFileController.java if you wish to troubleshoot.

// does the feature type already exist in the target?
try {
targetDataStore.getSchema(featureTypeName);
} catch (Exception e) {
LOGGER.info(
featureTypeName

  • " does not exist in data store "
  • storeName
  • “. Attempting to create it”);

// schema does not exist, create it by first creating an instance
// of the source datastore and copying over its schema
targetDataStore.createSchema(sourceDataStore.getSchema(featureTypeName));
sourceDataStore.getSchema(featureTypeName);
}

···


Jody Garnett

I use importer rest api.
So:
step 1: POST /geoserver/rest/imports (specifying target workspace and target datastore) to obtain an importID
step2: POST /geoserver/rest/imports//tasks (passing zip file into body) to obtain a taskID (zip is uploaded into geoserver data dir and is unzipped)
step3: PUT /geoserver/rest/imports//tasks//target to reset the target store for given taskID
step4: POST /geoserver/rest/imports/ to execute import

This sequence of operations create a table named as passed shapefile into given workspace/datastore;
if a table with same name already exists, created table is renamed appending number.

If between step2 and step3 I execute PUT geoserver/rest/imports//tasks/ passing
{

“layer”: {
“name”: “layer1”,
“title”: “layer1”
}
}
I could rename layer on geoserver with a different name than that of the table.

If between step2 and step3 I execute PUT geoserver/rest/imports//tasks/ passing

{
“task”: {
“updateMode”: “APPEND”
}
}
I could append data into existing table (named as uploaded shapefile)

I can’t find a way to insert data from uploaded shapefile shape.shp into a table which is called tableA (with same fields obviously)

It’s possible?
Thanks

Giuseppe

Il giorno mar 10 mag 2022 alle ore 06:33 Jody Garnett <jody.garnett@anonymised.com> ha scritto:

You may also consider using the resource rest api to upload the file, and the the importer rest api in ingest (it offers greater control as Ian suggests).

The upload you found determines a unique table name based on the provided content, so for your shapefile this is based on the filename.

The file is here https://github.com/geoserver/geoserver/blob/main/src/restconfig/src/main/java/org/geoserver/rest/catalog/DataStoreFileController.java if you wish to troubleshoot.

// does the feature type already exist in the target?
try {
targetDataStore.getSchema(featureTypeName);
} catch (Exception e) {
LOGGER.info(
featureTypeName

  • " does not exist in data store "
  • storeName
  • “. Attempting to create it”);

// schema does not exist, create it by first creating an instance
// of the source datastore and copying over its schema
targetDataStore.createSchema(sourceDataStore.getSchema(featureTypeName));
sourceDataStore.getSchema(featureTypeName);
}


Jody Garnett

On May 9, 2022 at 10:34:22 AM, Giuseppe Falcone <falcone.giuseppe@anonymised.com> wrote:

Hi
thanks for the response.
I’m building a web application that must have this function.
From browser user upload a shapefile e I put into a db table.
I think REST API are perfect for this purpose.

Giuseppe

Il giorno lun 9 mag 2022 alle ore 19:22 Ian Turton <ijturton@anonymised.com> ha scritto:

I’m not sure that you need to involve geoserver in this, Ogr2ogr would be quicker and easier to append a shapefile to a database. The GeoServer rest api is for creating data stores and layers etc not individual data management.

Alternatively you might be able to use the importer extension to do this but I’ve not used that in anger

Ian

On Mon, 9 May 2022, 17:25 Giuseppe Falcone, <falcone.giuseppe@anonymised.com> wrote:

Hi to all
I want with geoserver REST API put a shapefile into an existing postgis table.
I know how to load a shapefile into a postgis database, but I don’t know how I could indicate a specific table in which append data.
I Have a shapefile named tableA.shp; it’s possible put it’s data into a postgis table named tableB?
Thanks a lot

Giuseppe


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

I tried using the importer user interface using a shapefile, and while I can adjust the name of the layer being created, the result still has the native name unchanged.

So I think you are looking change to the code, it would be a nice change allowing user to define the name of the table being imported.

···


Jody Garnett

Thanks for you response.
I rephrase the question:
I have a web application where a user uploads a shapefile and this needs to be inserted into a postgis table that has the same fields (in append mode). Shapefile and table don’t necessarily have the same name.
There is a manner to execute this task via rest api or importer api?

Thanks

Giuseppe

Il giorno mer 11 mag 2022 alle ore 09:31 Jody Garnett <jody.garnett@anonymised.com> ha scritto:

I tried using the importer user interface using a shapefile, and while I can adjust the name of the layer being created, the result still has the native name unchanged.

So I think you are looking change to the code, it would be a nice change allowing user to define the name of the table being imported.


Jody Garnett

On May 10, 2022 at 12:14:37 AM, Giuseppe Falcone <falcone.giuseppe@anonymised.com> wrote:

I use importer rest api.
So:
step 1: POST /geoserver/rest/imports (specifying target workspace and target datastore) to obtain an importID
step2: POST /geoserver/rest/imports//tasks (passing zip file into body) to obtain a taskID (zip is uploaded into geoserver data dir and is unzipped)
step3: PUT /geoserver/rest/imports//tasks//target to reset the target store for given taskID
step4: POST /geoserver/rest/imports/ to execute import

This sequence of operations create a table named as passed shapefile into given workspace/datastore;
if a table with same name already exists, created table is renamed appending number.

If between step2 and step3 I execute PUT geoserver/rest/imports//tasks/ passing
{

“layer”: {
“name”: “layer1”,
“title”: “layer1”
}
}
I could rename layer on geoserver with a different name than that of the table.

If between step2 and step3 I execute PUT geoserver/rest/imports//tasks/ passing

{
“task”: {
“updateMode”: “APPEND”
}
}
I could append data into existing table (named as uploaded shapefile)

I can’t find a way to insert data from uploaded shapefile shape.shp into a table which is called tableA (with same fields obviously)

It’s possible?
Thanks

Giuseppe

Il giorno mar 10 mag 2022 alle ore 06:33 Jody Garnett <jody.garnett@anonymised.com> ha scritto:

You may also consider using the resource rest api to upload the file, and the the importer rest api in ingest (it offers greater control as Ian suggests).

The upload you found determines a unique table name based on the provided content, so for your shapefile this is based on the filename.

The file is here https://github.com/geoserver/geoserver/blob/main/src/restconfig/src/main/java/org/geoserver/rest/catalog/DataStoreFileController.java if you wish to troubleshoot.

// does the feature type already exist in the target?
try {
targetDataStore.getSchema(featureTypeName);
} catch (Exception e) {
LOGGER.info(
featureTypeName

  • " does not exist in data store "
  • storeName
  • “. Attempting to create it”);

// schema does not exist, create it by first creating an instance
// of the source datastore and copying over its schema
targetDataStore.createSchema(sourceDataStore.getSchema(featureTypeName));
sourceDataStore.getSchema(featureTypeName);
}


Jody Garnett

On May 9, 2022 at 10:34:22 AM, Giuseppe Falcone <falcone.giuseppe@anonymised.com> wrote:

Hi
thanks for the response.
I’m building a web application that must have this function.
From browser user upload a shapefile e I put into a db table.
I think REST API are perfect for this purpose.

Giuseppe

Il giorno lun 9 mag 2022 alle ore 19:22 Ian Turton <ijturton@anonymised.com> ha scritto:

I’m not sure that you need to involve geoserver in this, Ogr2ogr would be quicker and easier to append a shapefile to a database. The GeoServer rest api is for creating data stores and layers etc not individual data management.

Alternatively you might be able to use the importer extension to do this but I’ve not used that in anger

Ian

On Mon, 9 May 2022, 17:25 Giuseppe Falcone, <falcone.giuseppe@anonymised.com> wrote:

Hi to all
I want with geoserver REST API put a shapefile into an existing postgis table.
I know how to load a shapefile into a postgis database, but I don’t know how I could indicate a specific table in which append data.
I Have a shapefile named tableA.shp; it’s possible put it’s data into a postgis table named tableB?
Thanks a lot

Giuseppe


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

No it is a good feature request for importer; which I would love to see take on more functionality for updating tables. Right now it just keeps making table1, table2, table3 each time and there is not much control. There is also no way to clean up a table that was added by importer.

If you are interested in making a PR I would love to see this functionality added (there is also a range of commercial support options including my employer).

···


Jody Garnett

Use the REST API:

  • Set up the context and the shapefile to import
  • Use PUT requests against the context to update the import mode (APPEND) and change the target layer name (to the one you want to append to)
  • Run the import.

CheersAndrea

···

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail

Thanks a lot Andrea for the response, but I’m not able to do that

  1. POST http://10.23.8.193:8080/geoserver/rest/import to create task import

  2. POST http://10.23.8.193:8080/geoserver/rest/import//task to upload shapefile zip (multipart form-data)

  3. What is the body of PUT request /geoserver/rest/imports//tasks/ to change target layer name?
    I try:

{
“task”:{
“id”: 0,
“href”: “http://10.23.8.193:8080/geoserver/rest/imports/24/tasks/0”,
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”
}
}
}

(layerA is a layer on geoserver, on same workspace and same datastore having same fields of uploaded shapefile)
But I receive error “Cannot cast org.geoserver.importer.ImportTask to org.geoserver.catalog.StoreInfo”

Thanks a lot

Giuseppe

Il giorno dom 22 mag 2022 alle ore 17:17 Andrea Aime <andrea.aime@anonymised.com> ha scritto:

On Thu, May 19, 2022 at 9:47 AM Giuseppe Falcone <falcone.giuseppe@anonymised.com> wrote:

Thanks for you response.
I rephrase the question:
I have a web application where a user uploads a shapefile and this needs to be inserted into a postgis table that has the same fields (in append mode). Shapefile and table don’t necessarily have the same name.
There is a manner to execute this task via rest api or importer api?

Use the REST API:

  • Set up the context and the shapefile to import
  • Use PUT requests against the context to update the import mode (APPEND) and change the target layer name (to the one you want to append to)
  • Run the import.

CheersAndrea

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail

Hi Giuseppe,
close, but your JSON is one level off, you’re updating the task, so it’s the top level object in the request.
So it would be something like this:

{
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”
}

}

Checking a REST script I have handy, inside the layer I also have “nativeName” : “theNativeName” (check the value for nativeName from the layer REST representation).

Cheers
Andrea

···

Regards,

Andrea Aime

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail

Thanks

I try the PUT with this body

{
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”,
“nativeName”: “layerA”
}
}

I receive a 500 error with the message ‘updateMode’
I’m using geoserver 2.10.1

for layer REST representation do you mean the response of these?

http://10.23.8.193:8080/geoserver/rest/layers/layerA.html

Thanks

Giuseppe

Il giorno lun 23 mag 2022 alle ore 11:20 Andrea Aime <andrea.aime@anonymised.com> ha scritto:

Hi Giuseppe,
close, but your JSON is one level off, you’re updating the task, so it’s the top level object in the request.
So it would be something like this:

{
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”
}

}

Checking a REST script I have handy, inside the layer I also have “nativeName” : “theNativeName” (check the value for nativeName from the layer REST representation).

Cheers
Andrea

On Mon, May 23, 2022 at 11:05 AM Giuseppe Falcone <falcone.giuseppe@anonymised.com> wrote:

Thanks a lot Andrea for the response, but I’m not able to do that

  1. POST http://10.23.8.193:8080/geoserver/rest/import to create task import

  2. POST http://10.23.8.193:8080/geoserver/rest/import//task to upload shapefile zip (multipart form-data)

  3. What is the body of PUT request /geoserver/rest/imports//tasks/ to change target layer name?
    I try:

{
“task”:{
“id”: 0,
“href”: “http://10.23.8.193:8080/geoserver/rest/imports/24/tasks/0”,
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”
}
}
}

(layerA is a layer on geoserver, on same workspace and same datastore having same fields of uploaded shapefile)
But I receive error “Cannot cast org.geoserver.importer.ImportTask to org.geoserver.catalog.StoreInfo”

Thanks a lot

Giuseppe

Il giorno dom 22 mag 2022 alle ore 17:17 Andrea Aime <andrea.aime@anonymised.com> ha scritto:

On Thu, May 19, 2022 at 9:47 AM Giuseppe Falcone <falcone.giuseppe@anonymised.com> wrote:

Thanks for you response.
I rephrase the question:
I have a web application where a user uploads a shapefile and this needs to be inserted into a postgis table that has the same fields (in append mode). Shapefile and table don’t necessarily have the same name.
There is a manner to execute this task via rest api or importer api?

Use the REST API:

  • Set up the context and the shapefile to import
  • Use PUT requests against the context to update the import mode (APPEND) and change the target layer name (to the one you want to append to)
  • Run the import.

CheersAndrea

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail

Regards,

Andrea Aime

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail

Hi to all,

I think the exception is due to geoserver version:

24 mag 07:21:53 ERROR [geoserver.rest] -
com.thoughtworks.xstream.mapper.CannotResolveClassException: updateMode
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:79)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)

I tried the procedure on geoserver 2.20.2 and it’s ok
This is the sequence of operations:

  1. POST geoserver/rest/imports to create import; post the json

{
“import”: {
“targetStore”: {
“dataStore”: {
“name”: “store”
}
},
“targetWorkspace”: {
“workspace”: {
“name”: “ws”
}
}
}
}
return importID

  1. POST geoserver/rest/imports//tasks to create task; post form-data with shapefile zipped
    return taksID

  2. PUT geoserver/rest/imports//tasks/ to set append mode; post the json

{
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”,
“nativeName”: “layerA”
}
}
return 204 no content

  1. PUT geoserver/rest/imports//tasks//target to reset datastore; post the json

{
“dataStore”: {
“name”:“store”
}
}
return 204 no content

  1. POST geoserver/rest/imports/ with no body to execute import
    return 204 no content

the import is executed and data are in layerA layer!

Giuseppe

Il giorno lun 23 mag 2022 alle ore 14:26 Giuseppe Falcone <falcone.giuseppe@anonymised.com> ha scritto:

Thanks

I try the PUT with this body

{
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”,
“nativeName”: “layerA”
}
}

I receive a 500 error with the message ‘updateMode’
I’m using geoserver 2.10.1

for layer REST representation do you mean the response of these?

http://10.23.8.193:8080/geoserver/rest/layers/layerA.html

Thanks

Giuseppe

Il giorno lun 23 mag 2022 alle ore 11:20 Andrea Aime <andrea.aime@anonymised.com> ha scritto:

Hi Giuseppe,
close, but your JSON is one level off, you’re updating the task, so it’s the top level object in the request.
So it would be something like this:

{
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”
}

}

Checking a REST script I have handy, inside the layer I also have “nativeName” : “theNativeName” (check the value for nativeName from the layer REST representation).

Cheers
Andrea

On Mon, May 23, 2022 at 11:05 AM Giuseppe Falcone <falcone.giuseppe@anonymised.com.84…> wrote:

Thanks a lot Andrea for the response, but I’m not able to do that

  1. POST http://10.23.8.193:8080/geoserver/rest/import to create task import

  2. POST http://10.23.8.193:8080/geoserver/rest/import//task to upload shapefile zip (multipart form-data)

  3. What is the body of PUT request /geoserver/rest/imports//tasks/ to change target layer name?
    I try:

{
“task”:{
“id”: 0,
“href”: “http://10.23.8.193:8080/geoserver/rest/imports/24/tasks/0”,
“updateMode”: “APPEND”,
“layer”: {
“name”: “layerA”
}
}
}

(layerA is a layer on geoserver, on same workspace and same datastore having same fields of uploaded shapefile)
But I receive error “Cannot cast org.geoserver.importer.ImportTask to org.geoserver.catalog.StoreInfo”

Thanks a lot

Giuseppe

Il giorno dom 22 mag 2022 alle ore 17:17 Andrea Aime <andrea.aime@anonymised.com> ha scritto:

On Thu, May 19, 2022 at 9:47 AM Giuseppe Falcone <falcone.giuseppe@anonymised.com> wrote:

Thanks for you response.
I rephrase the question:
I have a web application where a user uploads a shapefile and this needs to be inserted into a postgis table that has the same fields (in append mode). Shapefile and table don’t necessarily have the same name.
There is a manner to execute this task via rest api or importer api?

Use the REST API:

  • Set up the context and the shapefile to import
  • Use PUT requests against the context to update the import mode (APPEND) and change the target layer name (to the one you want to append to)
  • Run the import.

CheersAndrea

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail

Regards,

Andrea Aime

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail