Android Question point in polygon with spatialite

Discussion in 'Android Questions' started by RB Smissaert, Jun 27, 2018.

Similar threads

B4A Code Snippet [B4X] [XUI] Faster* DrawPolygon Method
B4A Code Snippet [B4X] Google Geocoding REST API
B4A Library GoogleMapsExtras
B4A Library Spatialite
B4A Question Spatilite problems
  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Running this SQL in the spatialite gui application:

    SELECT ID FROM P_POINTS WHERE Within(GEOMETRY, polygonfromtext('POLYGON(-2.165476 52.604321, -2.167375 52.606777, -2.16444 52.606914, -2.163287 52.604595, -2.165476 52.604321)', 4326)) = 1

    Geometry is the column in P_POINTS holding lat/lon points as geometry blobs. This column is fine as tested with the AsText and x and y functions.

    This SQL should give me results but I get nil. No error though.

    Any idea what could be the problem here?

  2. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    If I simplify it:

    SELECT Within(Makepoint(-2.5, 51.5, 4326), polygonfromtext('POLYGON(-2 52, -2.5 51, -3 52, -2 52)', 4326))

    I get as result - 1 and I understand that means unknown.
    So, why doesn't this give me the result 1?
    Spatialite gui doesn't recognize ST_Within as a function and not sure what the difference is between Within and ST_Within.

  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    The problem lies with making the polygon blob as this Sub shows:

    Public Sub TestPolygon
    Dim strSQL As String
    Dim SPL_Stmt As Spatialite_Stmt
     strSQL = 
    "select 'Point: ' || hex(MakePoint(-2, 52, 4326)) || " & _
    "', Polygon: ' || hex(polygonfromtext('POLYGON(-2 52, -2.5 53, -3 52, -2 52)', 4326))"
     SPL_Stmt = SPL_DB.Prepare(strSQL)
    Log("Hex Point and Polygon: " & SPL_Stmt.ColumnString(0))
    End Sub
    I get this result:

    Hex Point and Polygon: Point: 0001E610000000000000000000C00000000000004A4000000000000000C00000000000004A407C0100000000000000000000C00000000000004A40FE, Polygon:

    I take it polygonfromtext produces Null, but MakePoint works OK.
    So, how should I produce this polygon blob?

  4. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    This works fine though:

    SELECT hex(polygonfromtext('POLYGON((-2 52,-2.5 53,-3 52,-2 52))', 4326))

    So problem seems to have been missing brackets and I think all fixed now.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice