Been using Jan-Erik's shape cls with my program and they work great. But I often find I have arrays of lat/lons that I want to create a polygon from for example: my_points= .array~of("8.919400 118.009485","8.920184 118.008687","8.909866 118.040771","8.901590 118.038006")
Currently I have to convert the array entries to a string to create the polygon. I want to create the polygon directly from the array. I modified the the polyshape.cls prepare method to do this as follows:
::methodprepareUseArgpolyLine, nofixpoly, xyz, dbugIfpolyLine='POLYLINE'ThenReturn .TrueIfdbug= .TrueThenCallTrace'?i'self~point= .Array~newIfpolyLine~objectName='an Array'ThenDoIf0<polyLine~ItemsThenDoi=1TopolyLine~ItemsIfpolyLine[ i ]~objectName='a Point'Thenself~point[ self~point~Items+1 ] = .Point~new(polyLine[ i ] )ElseIfpolyLine[ i ]~objectName='a Line'Thenself~append(polyLine[ i ] )Elsedo--NEWParseValuepolyLine[ i ] Withlatlonself~point[ self~point~Items+1 ] = .Point~new(lon,lat)endEndEnd
So now if I code:
my_points= .array~of("8.919400 118.009485","8.920184 118.008687","8.909866 118.040771","8.901590 118.038006")
curr_polyon = .PolyShape~new(my_points)
say 'curr_polyon='curr_polyon
say 'Tostring='curr_polyon~toString(,,.true)
The result is:
curr_polyon=a Polygon
Tostring=118.009485,8.9194,0 118.008687,8.920184,0 118.040771,8.909866,0 118.038006,8.90159,0 118.009485,8.9194,0
Can this be implemented permanently, probably into the WGS84.cls ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I understand Jan wants this to run on OS2 and
I am not familiar with the OS2 ooRexx but:
Why wouldn't you subclass the polyshape class and do something like
this untested variant instead of asking your stuff to be incorporated:
::class myPolyShape public subclass polyShape
::method prepare
Use Arg polyLine, nofixpoly, xyz, dbug
If polyLine = 'POLYLINE' Then
Return .True
If dbug = .True Then Call Trace '?i'
self~point = .Array~new
If polyLine~objectName = 'an Array' Then
-- I would use polyLine~class~id = 'Array' because objectName is mutable
Do
-- This If superfluous
If 0 < polyLine~Items Then
Do i = 1 To polyLine~Items
objName = polyLine[ i ]~objectName
-- again replace objectName with class~id and 'Point' and 'Line'
If (objName='a Point' | objName='a Line') Then
prepare:super(polyLine, nofixpoly, xyz, dbug)
Else Do -- NEW
Parse Value polyLine[ i ] With lat lon
-- What's wrong with self~point~append(.Point~new(lot, lan)
self~point[ self~point~Items + 1 ] = .Point~new(lon,lat )
End
End
End
Hope this helps in some way
Ruurd
On 2/14/22 19:46, Paul Higgins wrote:
Been using Jan-Erik's shape cls with my program and they work great.
But I often find I have arrays of lat/lons that I want to create a
polygon from for example:
|my_points= .array~of("8.919400 118.009485","8.920184
118.008687","8.909866 118.040771","8.901590 118.038006")|
Currently I have to convert the array entries to a string to create
the polygon. I want to create the polygon directly from the array. I
modified the the polyshape.cls prepare method to do this as follows:
|::method prepare Use Arg polyLine, nofixpoly, xyz, dbug If polyLine =
'POLYLINE' Then Return .True If dbug = .True Then Call Trace '?i'
self~point = .Array~new If polyLine~objectName = 'an Array' Then Do If
0 < polyLine~Items Then Do i = 1 To polyLine~Items If polyLine[ i
]~objectName = 'a Point' Then self~point[ self~point~Items + 1 ] =
.Point~new( polyLine[ i ] ) Else If polyLine[ i ]~objectName = 'a
Line' Then self~append( polyLine[ i ] ) Else do -- NEW Parse Value
polyLine[ i ] With lat lon self~point[ self~point~Items + 1 ] =
.Point~new(lon,lat ) end End End |
So now if I code:
|my_points= .array~of("8.919400 118.009485","8.920184
118.008687","8.909866 118.040771","8.901590 118.038006") curr_polyon =
.PolyShape~new(my_points) say 'curr_polyon='curr_polyon say
'Tostring='curr_polyon~toString(,,.true) |
The result is:
curr_polyon=a Polygon
Tostring=118.009485,8.9194,0 118.008687,8.920184,0
118.040771,8.909866,0 118.038006,8.90159,0 118.009485,8.9194,0
Can this be implemented permanently, probably into the WGS84.cls ?
Or I could do it like this:
:~~~
:class myPolyShape public subclass polyShape
::method init
Use Arg polyLine, nofixpoly, xyz, dbug
points = .Array~new
Do i = 1 To polyLine~Items
Parse Value polyLine[ i ] With lat lon
points~append(.Point~new(lon,lat))
end
self~init:super( points, nofixpoly, xyz, dbug )
~~~
It works. Maybe better than overriding the prepare method
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Been using Jan-Erik's shape cls with my program and they work great. But I often find I have arrays of lat/lons that I want to create a polygon from for example:
my_points= .array~of("8.919400 118.009485","8.920184 118.008687","8.909866 118.040771","8.901590 118.038006")
Currently I have to convert the array entries to a string to create the polygon. I want to create the polygon directly from the array. I modified the the polyshape.cls prepare method to do this as follows:
So now if I code:
The result is:
curr_polyon=a Polygon
Tostring=118.009485,8.9194,0 118.008687,8.920184,0 118.040771,8.909866,0 118.038006,8.90159,0 118.009485,8.9194,0
Can this be implemented permanently, probably into the WGS84.cls ?
Hi,
I understand Jan wants this to run on OS2 and
I am not familiar with the OS2 ooRexx but:
Why wouldn't you subclass the polyshape class and do something like
this untested variant instead of asking your stuff to be incorporated:
::class myPolyShape public subclass polyShape
::method prepare
Use Arg polyLine, nofixpoly, xyz, dbug
If polyLine = 'POLYLINE' Then
Return .True
If dbug = .True Then Call Trace '?i'
self~point = .Array~new
If polyLine~objectName = 'an Array' Then
-- I would use polyLine~class~id = 'Array' because objectName is mutable
Do
-- This If superfluous
If 0 < polyLine~Items Then
Do i = 1 To polyLine~Items
objName = polyLine[ i ]~objectName
-- again replace objectName with class~id and 'Point' and 'Line'
If (objName='a Point' | objName='a Line') Then
prepare:super(polyLine, nofixpoly, xyz, dbug)
Else Do -- NEW
Parse Value polyLine[ i ] With lat lon
-- What's wrong with self~point~append(.Point~new(lot, lan)
self~point[ self~point~Items + 1 ] = .Point~new(lon,lat )
End
End
End
Hope this helps in some way
Ruurd
On 2/14/22 19:46, Paul Higgins wrote:
OK thanks Ruurd
Or I could do it like this:
:~~~
:class myPolyShape public subclass polyShape
::method init
Use Arg polyLine, nofixpoly, xyz, dbug
points = .Array~new
Do i = 1 To polyLine~Items
Parse Value polyLine[ i ] With lat lon
points~append(.Point~new(lon,lat))
end
self~init:super( points, nofixpoly, xyz, dbug )
~~~
It works. Maybe better than overriding the prepare method