User bio

Raj is a product manager at InterSystems focused on developer experience. He pioneered Web mapping-as-a-service in the late 1990s with Syncline, a startup he co-founded. After that he finished his PhD in Information Systems for Planning at MIT, creating a distributed computing architecture for urban information systems based on web services design patterns.

He then worked for a decade on spatial data interoperability challenges with the Open Geospatial Consortium helping governments work with software companies to share and manage geographic information for natural resource management, disaster relief, and defense coordination.

Prior to joining InterSystems, Raj worked in developer relations for database and data science cloud offerings at IBM.

Show all
Member since May 21, 2019

Using the the handy utility from @Alex Woodhead I was able to get something working. As of now you can get the Point, Line and Polygon code from but I can't guarantee those classes won't change in the future. I include demo code here to show:

  1. $LIST can be converted to a Python list using Py.Helper
  2. 2-dimensional $LISTs (a $LIST of $LISTs) didn't work without running them through the invoke ClassMethod you see below. 
  3. you can integrate with matplotlib to take advantage of the broad and deep range of functionality offered by probably the most popular graphics library around
Class geo.ToolsExample Extends %RegisteredObject

ClassMethod createPolygon() As geo.model.Polygon
    set l = ##class(geo.model.Line).%New()
    do l.addPoint(##class(geo.model.Point).%New(0.01,0.01))
    do l.addPoint(##class(geo.model.Point).%New(2.01,0.01))
    do l.addPoint(##class(geo.model.Point).%New(2.01,2.01))
    do l.addPoint(##class(geo.model.Point).%New(0.01,2.01))
    do l.addPoint(##class(geo.model.Point).%New(0.01,0.01))
    set polygon = ##class(geo.model.Polygon).%New()
    set polygon.line = l
    Return polygon

ClassMethod test()
    set polygon = ..createPolygon()
    set isin = ..PointInPolygon(polygon, ##class(geo.model.Point).%New(1.01,1.01))
    w isin,!
    set isout = ..PointInPolygon(polygon, ##class(geo.model.Point).%New(3.01,3.01))
    w isout,!

ClassMethod PointInPolygon(poly As geo.model.Polygon, pt As geo.model.Point) As %Boolean
    set mp = ##class(%SYS.Python).Import("matplotlib")
    set mpltPath = mp.path
    set polylist = poly.getAsList()
    set nothing = ##class(Py.Helper).toPyListOrString(polylist,.poly2)
    set point = ##class(Py.Helper).toPyListOrString(pt.getAsList())
    set path = ..invoke(mpltPath,poly2)
    Return path."contains_point"(point)

ClassMethod invoke(ByRef mpltPath As %SYS.Python, ByRef poly2) As %SYS.Python [ Language = python ]
    return mpltPath.Path(poly2)


That would certainly work, but my use case is geographic data and a natural feature (e.g. a river or a coastline) could be composed of thousands of Points, so I want something more performance-oriented than JSON.

Open Exchange applications:
Global Masters badges: