Support Topics Documentation Slack YouTube Blog

Unable to update spatial data point?

I have a table with a column named “location” of type POINT WGS 84. I want to update the value of a single column in a single row in that table. This is my code:

        MapDrivenDataStore *dataStore = [Backendless.shared.data ofTable:[self getSignalsTableName]];
        [dataStore findByIdWithObjectId:signal.signalId responseHandler:^(NSDictionary<NSString *,id> * _Nonnull signalMap) {            
        NSMutableDictionary *updatedSignalMap = [NSMutableDictionary dictionaryWithDictionary:signalMap];
        [updatedSignalMap setObject:[NSNumber numberWithUnsignedInteger:status] forKey:kField_Status];
        [dataStore updateWithEntity:updatedSignalMap
            responseHandler:^(NSDictionary<NSString *,id> * _Nonnull updatedSignal) {
                [self sendPushNotificationsForNewStatus:status onSignal:signal withCurrentComments:currentComments];
                signal.status = status;
                completion(nil);
            } errorHandler:^(Fault * _Nonnull fault) {
                FINError *error = [[FINError alloc] initWithMessage:fault.message];
                completion(error);
            }];
    } errorHandler:^(Fault * _Nonnull fault) {
        FINError *error = [[FINError alloc] initWithMessage:fault.message];
        completion(error);
    }];

However, upon execution I get the following error:

Error Domain=BackendlessErrorDomain Code=0 “Can not create BackendlessGeometry from type weborb.reader.CacheableAdaptingTypeWrapper” UserInfo={NSLocalizedDescription=Can not create BackendlessGeometry from type weborb.reader.CacheableAdaptingTypeWrapper}

If I try to convert the “location” value (which is of type BLPoint) to GeoJSON like this:

    BLPoint *blPoint = [updatedSignalMap objectForKey:kField_Location];
    NSDictionary *jsonPoint = [blPoint asGeoJson];
    [updatedSignalMap setObject:jsonPoint forKey:kField_Location];

I get the same error:

Error Domain=BackendlessErrorDomain Code=0 “Can not create BackendlessGeometry from type weborb.reader.CacheableAdaptingTypeWrapper” UserInfo={NSLocalizedDescription=Can not create BackendlessGeometry from type weborb.reader.CacheableAdaptingTypeWrapper}

Converting to WKT point:

    BLPoint *blPoint = [updatedSignalMap objectForKey:kField_Location];
    NSString *wktPoint = [blPoint asWkt];
    [updatedSignalMap setObject:wktPoint forKey:kField_Location];

returns:

Error Domain=BackendlessErrorDomain Code=0 “Can not create BackendlessGeometry from type weborb.reader.StringType” UserInfo={NSLocalizedDescription=Can not create BackendlessGeometry from type weborb.reader.StringType}

So, how am I supposed to update a table with a spatial data column in it!?
Also, is it possible to update only a single column without sending the rest of the columns in the dictionary? Currently this results in deleting their values.

Hello @milen-marinov

What version of SDK are you using?

Hello,

I’m using BackendlessSwift 6.0

I have also checked the same thing in Android (SDK com.backendless:backendless:6.0.1) where it behaves in the same way.

Hello @milen-marinov

I try to reproduce in Android (SDK com.backendless:backendless:6.0.1):

  1. Create new application.
  2. Create table Table1 (add 2 coulumns: location-Point and name-String)
  3. Add one object to Table1:
{
	"name": "name1",
	"location": {
		"type": "Point",
		"coordinates": [
			11.11,
			22.22
		],
		"srsId": 4326,
		"___class": "com.backendless.persistence.Point"
	}
}
  1. Call from Android:
    Map<String, Object> objectMap = new HashMap<>();
    objectMap.put( "objectId", <objectId> );
    Point point = new Point();
    point.setLongitude( 12.34 );
    point.setLatitude( 56.78 );
    objectMap.put( "location", point );
    Map<String, Object> response = Backendless.Persistence.of( "Table1" ).save( objectMap );
    System.out.println( response );

response:

{created=Mon Sep 14 12:51:26 EEST 2020, name=name1, ___class=Table1, location='POINT(12.34 56.78)', ownerId=null, updated=Mon Sep 14 13:19:07 EEST 2020, objectId=2E0FD1BC-1878-4A3A-88A9-B17BD8C5C7ED}

and in console i see changed object.

Also i test in REST:
PUT
https://api.backendless.com/<appId>/<rest-api-key>/data/Table1/<objectId>

{
	"location":
	{
		"type": "Point",
		"coordinates": [ 10.10, 20.20 ]
	}  
}

response:

{
    "created": 1600077086000,
    "name": "name1",
    "___class": "Table1",
    "location": {
        "type": "Point",
        "coordinates": [
            10.1,
            20.2
        ],
        "srsId": 4326,
        "___class": "com.backendless.persistence.Point"
    },
    "ownerId": null,
    "updated": 1600077927000,
    "objectId": "2E0FD1BC-1878-4A3A-88A9-B17BD8C5C7ED"
}

and in console i see changed object.

Please, provide your Android code with which you have this error.

Hi,

Here is the Android code:

    Backendless.Persistence.of(getTableName()).findById(signalId, new AsyncCallback<Map>() {
        @Override
        public void handleResponse(Map response) {
            response.put(SIGNAL_STATUS, status);

            Backendless.Persistence.of(getTableName()).save(response, new AsyncCallback<Map>() {
                @Override
                public void handleResponse(Map saveResponse) {
                    // Update signal in database
                    //...

                    callback.onStatusUpdated(status);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    callback.onStatusFailure(fault.getMessage());
                }
            });
        }

        @Override
        public void handleFault(BackendlessFault fault) {
            callback.onStatusFailure(fault.getMessage());
        }
    });

However, I did some more testing and found that the issue is related to (but not directly caused by) an event handler beforeUpdate that I have for this table. If I disable this event handler everything goes fine. If I enable it the operation fails with the above mentioned errors. However, when I run the event handler in remote debug mode the operation fails before entering the beforeUpdate method. So it looks like the problem is not in my code but somewhere in the cloud code that’s executed before it.

My AppId is BDCD56B9-351A-E067-FFA4-9EA9CF2F4000, the table is SignalsTest, and the event handler is beforeUpdate in the status_update model. As implied by the name the table is for test purposes so you play with it safely.

Best,
Milen

Hello @milen-marinov

I reproduced the issue.
The internal ticket (BKNDLSS-22728) has been created. Your problem will be investigated and fixed as soon as possible.

1 Like