Select to view content in your preferred language

Extracting coordinates from string

796
2
01-15-2018 02:27 PM
RasmusJensen
Occasional Contributor

Hello, 

I've got strings like this streaming into my geoevent server. (10.5.1)

{protocol":"RTCU,"id"":""218244290","gps"":""$GPRMC,220359.00,A,5546.4919,N,01230.3042,E,0.0,0.0,150118,0.0E,A*05","distatus"":""0;0;0;0;0;0","aistatus"":""0;0;0;0","volt"":""139","event"":""MAXPER","batt"":""5","temp"":""1200","ts"":""1200521038""}

{protocol":"RTCU,"id"":""218244290","gps"":""$GPRMC,215513.00,A,5546.4919,N,01230.3042,E,0.0,0.0,150118,0.0E,A*05","distatus"":""0;0;0;0;0;0","aistatus"":""0;0;0;0","volt"":""139","event"":""MAXPER","batt"":""5","temp"":""1200","ts"":""1200520513""}

(yes the vehicle is stationary at the moment)

The coordinates are in the string (needs division with 100 tho) and I need to extract these coordinates (5546.4919,N,01230.3042,E) and create point features from them.

But I am quite lost. It seems that Field Calculator using RegEx would be the proper processor to use, but I cant get it to do what I expect it to do. 

Any help would be greatly appreciated!!

br,

Rasmus

0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

Your pattern seems regular, hence.... the 's' in the following, substitute it with !YourFieldName!  ..   Use the python parser and use the following in the field calculator on a string field

"{}{} {}{}".format(*(s.split(":")[3].split(",")[3:7]))

result

'5546.4919N 01230.3042E'

If you want to get fancy and put the easting and northings in separate fields, upscaled to floating point numbers, then you have the basis at least to formulate a function (aka, def ) to use in the field calculator

RasmusJensen
Occasional Contributor

I did endd up using RegEx after all. But the was used to solve another isse 🙂

0 Kudos