undefinedfix
Sign in

The problem of precision loss of multipolygon in MySQL

pianojoe edited in Fri, 23 Sep 2022

1. This is the geometryjson data transferred from the front end to the background

{
    "type":"FeatureCollection",
    "name":"沙二新村_bd09",
    "crs":{
        "type":"name",
        "properties":{
            "name":"urn:ogc:def:crs:OGC:1.3:CRS84"
        }
    },
    "features":[
        {
            "type":"Feature",
            "properties":{
                "FID_":0,
                "RefName":"沙二新村"
            },
            "geometry":{
                "type":"MultiPolygon",
                "coordinates":[
                    [
                        [
                            [
                                113.83611553907443,
                                22.78082228953826
                            ],
                            [
                                113.83615270105246,
                                22.781330941487614
                            ],
                            [
                                113.83619535231993,
                                22.78190835622712
                            ],
                            [
                                113.8359391610967,
                                22.782145517940965
                            ],
                            [
                                113.83591004030475,
                                22.782364678602836
                            ],
                            [
                                113.83658110575651,
                                22.782267444330923
                            ],
                            [
                                113.83672580349621,
                                22.782270941010097
                            ],
                            [
                                113.83682427457647,
                                22.782807961272
                            ],
                            [
                                113.83716712152268,
                                22.78283407226441
                            ],
                            [
                                113.83729315640223,
                                22.782854716397498
                            ],
                            [
                                113.83733392965138,
                                22.78282995924141
                            ],
                            [
                                113.83761016289067,
                                22.782915224894865
                            ],
                            [
                                113.8377214136748,
                                22.78297218779456
                            ],
                            [
                                113.8377966263927,
                                22.782996761533248
                            ],
                            [
                                113.8379745545071,
                                22.783053479055813
                            ],
                            [
                                113.83805100486087,
                                22.783048658546235
                            ],
                            [
                                113.83896527379136,
                                22.78290436825743
                            ],
                            [
                                113.83894148813191,
                                22.782644899002072
                            ],
                            [
                                113.83887602031581,
                                22.782050346550623
                            ],
                            [
                                113.8385989725796,
                                22.78079161111866
                            ],
                            [
                                113.8379288314515,
                                22.779433504844047
                            ],
                            [
                                113.83610339368849,
                                22.780792291590767
                            ],
                            [
                                113.83611553907443,
                                22.78082228953826
                            ]
                        ]
                    ]
                ]
            }
        }
    ]
}

two . However, after the geometryjson data was converted into multipolygon objects, I found that the accuracy of coordinate data was lost.

MULTIPOLYGON(((113.836115539074427, 22.780822289538261 ], [ 113.836152701052455, 22.781330941487614 ], [ 113.836195352319933, 22.78190835622712 ], [ 113.835939161096704, 22.782145517940965 ], [ 113.835910040304753, 22.782364678602836 ], [ 113.836581105756508, 22.782267444330923 ], [ 113.836725803496208, 22.782270941010097 ], [ 113.836824274576472, 22.782807961271999 ], [ 113.837167121522683, 22.782834072264411 ], [ 113.837293156402225, 22.782854716397498 ], [ 113.837333929651379, 22.782829959241411 ], [ 113.83761016289067, 22.782915224894865 ], [ 113.837721413674799, 22.782972187794559 ], [ 113.837796626392702, 22.782996761533248 ], [ 113.837974554507099, 22.783053479055813 ], [ 113.838051004860873, 22.783048658546235 ], [ 113.838965273791359, 22.78290436825743 ], [ 113.838941488131908, 22.782644899002072 ], [ 113.838876020315809, 22.782050346550623 ], [ 113.838598972579604, 22.780791611118659 ], [ 113.837928831451507, 22.779433504844047 ], [ 113.836103393688489, 22.780792291590767 ], [ 113.836115539074427, 22.780822289538261 )))

3. My transformation method is as follows

MultiPolygon multiPolygon=null;
    Map paramGeom = villageDetailParams.getGeom();
    if(paramGeom!=null&&paramGeom.get("coordinates")!=null){
      String jsonString = JSONObject.toJSONString(paramGeom);
      log.info("geom:{}",jsonString);
      GeometryJSON geometryJSON = new GeometryJSON();
      try {
        StringReader stringReader = new StringReader(jsonString);
        multiPolygon= geometryJSON.readMultiPolygon(stringReader);
        baseVillage.setGeom(multiPolygon);
      } catch (Exception e) {
        log.info("处理村geom异常:{}",e.getMessage());
        throw new RuntimeException("处理村geom异常");
      }
    }

Ask what caused it

0 Replies