336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
회사에서 표준 포맷 작업을 하다.
boost가 잘되어 있는거 같아서
boost를 이용해서 작업해 보았습니다
아마도 함수 몇개만 바꾸면 json,xml,ini,info,svg, wkb, wkt, shp, kml, gml 지원 하실수 있을걸로 생각 됩니다
전 json에 들어 있는 wkt를 대상으로 테스트 해 보았습니다 ^^
boost geometry는 boost-geometry-0.8.0을 이용 했고요
파서 만드는 삽질을 줄었으면 좋겠습니다
--테스트 json 데이터 --
{
"geom": {
"geom_id": "-1",
"layer_id": "200002",
"theme_value": "0",
"label_field_value": "0",
"label_alignment_field_value": "0",
"label_angle_field_value": "0",
"angle_field_value_size": "0",
"point_Angle": "0",
"geom_type": "LINESTRING",
"geom": "LINESTRING(14104231.0354653 4423639.84986766,14104228.4684818 4423642.07296706)"
},
"geom": {
"geom_id": "-2",
"layer_id": "200002",
"theme_value": "0",
"label_field_value": "0",
"label_alignment_field_value": "0",
"label_angle_field_value": "0",
"angle_field_value_size": "0",
"point_Angle": "0",
"geom_type": "MULTIPOLYGON",
"geom": "MULTIPOLYGON(((14119816.3585382 4075496.44284681,14119864.9304208 4075401.76688298,14119959.6915541 4075135.80080068,14120034.9150242 4075025.19037725,14120254.0950199 4074889.52620539,14120321.983183 4074813.06409484,14120329.4606865 4074638.03285781,14120238.8632291 4074540.63620682,14120133.6977321 4074485.85014266,14120034.872647 4074221.83700132,14119981.7499128 4074167.08547386,14119837.846308 4074114.62978278,14119785.9454082 4074046.51246855,14119792.2223009 4073894.58460197,14119838.3275501 4073841.2408202,14119989.5641773 4073787.9738294,14120103.5669908 4073620.4894686,14120118.2248227 4073552.35295779,14120055.4906736 4073428.39979631,14119875.4570205 4073256.72829576,14119875.5019996 4073226.33675493,14119815.1557362 4073166.67949882,14119785.1363883 4073013.61477931,14119680.1821717 4072846.84269082,14119656.2792143 4072648.84420541,14119716.9897748 4072511.57375424,14119724.5120672 4072307.40458721,14119512.876472 4071554.97273197,14119425.9965979 4071390.76888211,14119369.1891489 4071370.03718935,14119331.6598439 4071396.68336523,14119308.4857702 4071518.23156919,14119339.535311 4071790.40453332,14119324.3568751 4072170.76869271,14119249.0319346 4072368.71575532,14119218.5292596 4072535.05098008,14119218.3432179 4072679.70682217,14119264.0180749 4072854.75275855,14119233.1865566 4073210.7357901,14119278.9102439 4073355.39794875,14119362.2887739 4073455.17614324,14119472.0075173 4073657.09505294,14119505.5812595 4073856.542391,14119483.6793143 4073932.99067128,14119376.8680927 4074144.28800909,14119210.877447 4074289.85054997,14119150.1601428 4074425.92360448,14119127.6055713 4074949.64419915,14119142.9276325 4075163.5853945,14119204.3987212 4075330.26230711,14119347.1883894 4075300.04353859,14119393.1562633 4075303.84096407,14119460.6894086 4075481.34953048,14119588.9741836 4075436.59330508,14119618.0285757 4075412.31334112,14119665.2518174 4075420.82953741,14119695.4210203 4075446.40877588,14119732.8465966 4075519.45597451,14119816.3585382 4075496.44284681)))"
}
}
-- 테스트 데이터 끝 --
--include 추가 --
//boost
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/multi/geometries/multi_point.hpp>
#include <boost/geometry/multi/geometries/multi_linestring.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/point.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/box.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/ring.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/polygon.hpp>
#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
--함수 본문 --
void SetGeometry(LPCTSTR jsonData)
{
typedef boost::geometry::model::d2::point_xy<double> boost_points;
typedef boost::geometry::model::linestring<boost_points> boost_linestring;
typedef boost::geometry::model::polygon<boost_points> boost_polygon;
typedef boost::geometry::model::linear_ring<boost_points> liner_ring;
typedef boost::geometry::model::multi_point<boost_points> boost_multi_points;
typedef boost::geometry::model::multi_linestring<boost_linestring> boost_multi_linestring;
typedef boost::geometry::model::multi_polygon<boost_polygon> boost_multi_polygon;
//트리선언
boost::property_tree::ptree pt;
//데이터 std쪽으로 변환
std::stringstream stream(jsonData);
//실제 파싱 함수 바꾸면 xml,ini,info 지원
boost::property_tree::json_parser::read_json(stream, pt);
//상위 트리 루프
BOOST_FOREACH(boost::property_tree::ptree::value_type & v, pt)
{
//하위 트리 루프
BOOST_FOREACH(boost::property_tree::ptree::value_type & v2, v.second)
{
//키값, 데이터
const TCHAR * key = v2.first.c_str(),
* data = v2.second.data().c_str();
//출력창 표시
TRACE("%s %s \n", key, data);
//geometry 정보인지 ?
if(_tcscmp(key, _T("geom")) == 0)
{
//geom_type값에 접근해서 해당 타입 취득
const TCHAR * type = v.second.get_child(_T("geom_type")).data().c_str() ;
//svg, wkb, shp(?), kml, gml도 지원
if(_tcscmp(type, _T("POINT")) == 0)
{
boost_points geom;
boost::geometry::read_wkt(data, geom);
TRACE("%f %f\n", geom.x(), geom.y());
}
else if(_tcscmp(type, _T("LINESTRING")) == 0)
{
boost_linestring geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_points & points, geom)
{
TRACE("%f %f\n", points.x(), points.y());
}
}
else if(_tcscmp(type, _T("POLYGON")) == 0)
{
boost_polygon geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_points & points, geom.outer())
{
TRACE("outer %f %f\n", points.x(), points.y());
}
BOOST_FOREACH(liner_ring & ring, geom.inners())
{
BOOST_FOREACH(boost_points & points, ring)
{
TRACE("inners %f %f\n", points.x(), points.y());
}
}
}
else if(_tcscmp(type, _T("MULTIPOINTS")) == 0)
{
boost_multi_points geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_points & points, geom)
{
TRACE("%f %f\n", points.x(), points.y());
}
}
else if(_tcscmp(type, _T("MULTILINESTRING")) == 0)
{
boost_multi_linestring geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_linestring & lines, geom)
{
BOOST_FOREACH(boost_points & points, lines)
{
TRACE("%f %f\n", points.x(), points.y());
}
}
}
else if(_tcscmp(type, _T("MULTIPOLYGON")) == 0)
{
boost_multi_polygon geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_polygon & polygon, geom)
{
BOOST_FOREACH(boost_points & points, polygon.outer())
{
TRACE("outer %f %f\n", points.x(), points.y());
}
BOOST_FOREACH(liner_ring & ring, polygon.inners())
{
BOOST_FOREACH(boost_points & points, ring)
{
TRACE("inners %f %f\n", points.x(), points.y());
}
}
}
}
}
}
}
}
boost가 잘되어 있는거 같아서
boost를 이용해서 작업해 보았습니다
아마도 함수 몇개만 바꾸면 json,xml,ini,info,svg, wkb, wkt, shp, kml, gml 지원 하실수 있을걸로 생각 됩니다
전 json에 들어 있는 wkt를 대상으로 테스트 해 보았습니다 ^^
boost geometry는 boost-geometry-0.8.0을 이용 했고요
파서 만드는 삽질을 줄었으면 좋겠습니다
--테스트 json 데이터 --
{
"geom": {
"geom_id": "-1",
"layer_id": "200002",
"theme_value": "0",
"label_field_value": "0",
"label_alignment_field_value": "0",
"label_angle_field_value": "0",
"angle_field_value_size": "0",
"point_Angle": "0",
"geom_type": "LINESTRING",
"geom": "LINESTRING(14104231.0354653 4423639.84986766,14104228.4684818 4423642.07296706)"
},
"geom": {
"geom_id": "-2",
"layer_id": "200002",
"theme_value": "0",
"label_field_value": "0",
"label_alignment_field_value": "0",
"label_angle_field_value": "0",
"angle_field_value_size": "0",
"point_Angle": "0",
"geom_type": "MULTIPOLYGON",
"geom": "MULTIPOLYGON(((14119816.3585382 4075496.44284681,14119864.9304208 4075401.76688298,14119959.6915541 4075135.80080068,14120034.9150242 4075025.19037725,14120254.0950199 4074889.52620539,14120321.983183 4074813.06409484,14120329.4606865 4074638.03285781,14120238.8632291 4074540.63620682,14120133.6977321 4074485.85014266,14120034.872647 4074221.83700132,14119981.7499128 4074167.08547386,14119837.846308 4074114.62978278,14119785.9454082 4074046.51246855,14119792.2223009 4073894.58460197,14119838.3275501 4073841.2408202,14119989.5641773 4073787.9738294,14120103.5669908 4073620.4894686,14120118.2248227 4073552.35295779,14120055.4906736 4073428.39979631,14119875.4570205 4073256.72829576,14119875.5019996 4073226.33675493,14119815.1557362 4073166.67949882,14119785.1363883 4073013.61477931,14119680.1821717 4072846.84269082,14119656.2792143 4072648.84420541,14119716.9897748 4072511.57375424,14119724.5120672 4072307.40458721,14119512.876472 4071554.97273197,14119425.9965979 4071390.76888211,14119369.1891489 4071370.03718935,14119331.6598439 4071396.68336523,14119308.4857702 4071518.23156919,14119339.535311 4071790.40453332,14119324.3568751 4072170.76869271,14119249.0319346 4072368.71575532,14119218.5292596 4072535.05098008,14119218.3432179 4072679.70682217,14119264.0180749 4072854.75275855,14119233.1865566 4073210.7357901,14119278.9102439 4073355.39794875,14119362.2887739 4073455.17614324,14119472.0075173 4073657.09505294,14119505.5812595 4073856.542391,14119483.6793143 4073932.99067128,14119376.8680927 4074144.28800909,14119210.877447 4074289.85054997,14119150.1601428 4074425.92360448,14119127.6055713 4074949.64419915,14119142.9276325 4075163.5853945,14119204.3987212 4075330.26230711,14119347.1883894 4075300.04353859,14119393.1562633 4075303.84096407,14119460.6894086 4075481.34953048,14119588.9741836 4075436.59330508,14119618.0285757 4075412.31334112,14119665.2518174 4075420.82953741,14119695.4210203 4075446.40877588,14119732.8465966 4075519.45597451,14119816.3585382 4075496.44284681)))"
}
}
-- 테스트 데이터 끝 --
--include 추가 --
//boost
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/multi/geometries/multi_point.hpp>
#include <boost/geometry/multi/geometries/multi_linestring.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/point.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/box.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/ring.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon/polygon.hpp>
#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
--함수 본문 --
void SetGeometry(LPCTSTR jsonData)
{
typedef boost::geometry::model::d2::point_xy<double> boost_points;
typedef boost::geometry::model::linestring<boost_points> boost_linestring;
typedef boost::geometry::model::polygon<boost_points> boost_polygon;
typedef boost::geometry::model::linear_ring<boost_points> liner_ring;
typedef boost::geometry::model::multi_point<boost_points> boost_multi_points;
typedef boost::geometry::model::multi_linestring<boost_linestring> boost_multi_linestring;
typedef boost::geometry::model::multi_polygon<boost_polygon> boost_multi_polygon;
//트리선언
boost::property_tree::ptree pt;
//데이터 std쪽으로 변환
std::stringstream stream(jsonData);
//실제 파싱 함수 바꾸면 xml,ini,info 지원
boost::property_tree::json_parser::read_json(stream, pt);
//상위 트리 루프
BOOST_FOREACH(boost::property_tree::ptree::value_type & v, pt)
{
//하위 트리 루프
BOOST_FOREACH(boost::property_tree::ptree::value_type & v2, v.second)
{
//키값, 데이터
const TCHAR * key = v2.first.c_str(),
* data = v2.second.data().c_str();
//출력창 표시
TRACE("%s %s \n", key, data);
//geometry 정보인지 ?
if(_tcscmp(key, _T("geom")) == 0)
{
//geom_type값에 접근해서 해당 타입 취득
const TCHAR * type = v.second.get_child(_T("geom_type")).data().c_str() ;
//svg, wkb, shp(?), kml, gml도 지원
if(_tcscmp(type, _T("POINT")) == 0)
{
boost_points geom;
boost::geometry::read_wkt(data, geom);
TRACE("%f %f\n", geom.x(), geom.y());
}
else if(_tcscmp(type, _T("LINESTRING")) == 0)
{
boost_linestring geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_points & points, geom)
{
TRACE("%f %f\n", points.x(), points.y());
}
}
else if(_tcscmp(type, _T("POLYGON")) == 0)
{
boost_polygon geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_points & points, geom.outer())
{
TRACE("outer %f %f\n", points.x(), points.y());
}
BOOST_FOREACH(liner_ring & ring, geom.inners())
{
BOOST_FOREACH(boost_points & points, ring)
{
TRACE("inners %f %f\n", points.x(), points.y());
}
}
}
else if(_tcscmp(type, _T("MULTIPOINTS")) == 0)
{
boost_multi_points geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_points & points, geom)
{
TRACE("%f %f\n", points.x(), points.y());
}
}
else if(_tcscmp(type, _T("MULTILINESTRING")) == 0)
{
boost_multi_linestring geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_linestring & lines, geom)
{
BOOST_FOREACH(boost_points & points, lines)
{
TRACE("%f %f\n", points.x(), points.y());
}
}
}
else if(_tcscmp(type, _T("MULTIPOLYGON")) == 0)
{
boost_multi_polygon geom;
boost::geometry::read_wkt(data, geom);
BOOST_FOREACH(boost_polygon & polygon, geom)
{
BOOST_FOREACH(boost_points & points, polygon.outer())
{
TRACE("outer %f %f\n", points.x(), points.y());
}
BOOST_FOREACH(liner_ring & ring, polygon.inners())
{
BOOST_FOREACH(boost_points & points, ring)
{
TRACE("inners %f %f\n", points.x(), points.y());
}
}
}
}
}
}
}
}
'글 > GIS' 카테고리의 다른 글
arcgis용 epsg 900913 prj 파일입니다 (0) | 2011.11.10 |
---|---|
arcobject에서 현재 선택된 영역 가져오는 법입니다 (0) | 2010.05.11 |
도분초 -> 구글 좌표 (127.xxxxxx , 36.xxxxxx) 변환 하는 방법 입니다 (0) | 2010.02.18 |
ArcObject를 이용해서 command(addon) 만드는 법 입니다 (0) | 2010.01.05 |
ArcObject에 대한 설명 .. (2) | 2009.12.31 |