2013-03-18 3 views
5

다각형이 WKT 형식으로 저장된 MySQL 데이터베이스로 작업하고 있습니다. 데이터베이스의 많은 폴리곤에는 중복 포인트가 있습니다 (예 : 아래 예에서 -122.323502 47.600959가 세 번 반복됨).다각형에 오류가있을 때 WKT에서 RGeo 다각형을 만드는 방법

이 폴리곤에서 RGeo :: Cartesian :: Factory.parse_wkt()를 호출 할 때 결과는 nil입니다.

어떻게 다각형 데이터를 수정하지 않고도이 다각형으로부터 RGeo 개체를 만들 수 있습니까?

poly = "MULTIPOLYGON(((-122.362163 47.618641,-122.344621 47.592555,-122.332017 47.592458,-122.32748 47.59241,-122.326109 47.592652,-122.324738 47.592895,-122.323147 47.593478,-122.321412 47.59411,-122.320826 47.594984,-122.320669 47.596296,-122.321149 47.598627,-122.323502 47.600959,-122.323502 47.600959,-122.323502 47.600959,-122.324071 47.601688,-122.320757 47.601688,-122.32073 47.604262,-122.320767 47.607663,-122.320746 47.609703,-122.320723 47.611938,-122.320714 47.612812,-122.320772 47.614075,-122.320799 47.618495,-122.362163 47.618641)))" 

parsed_poly = RGeo::Cartesian::Factory.new().parse_wkt(poly) 

=>nil 
+0

"직교 좌표계"는 x/y ("평면 지구", euclidean) 좌표를 의미합니다. 당신은 지리적 좌표 ("곡선 지구", 타원형)로 전달하고 있습니다. 잘못된 공장을 사용하고 있습니다. –

답변

6

이 시도 :

RGeo::Geos.factory(:srid => 4326).parse_wkt(wkt_string) 
+0

나는'RGeo :: Geographic.spherical_factory (: srid => 4326)'도 알고 있지만 RGeo에 관해서는 100 % 확실한 차이는없는 것으로 알고 있습니다. – daybreaker

1
polygon = RGeo::Geographic.spherical_factory.parse_wkt(params[:polygon]) 

작품을 나를 위해! 나는이 같은 레일의 위치 기록을 만들려고

먼저에는 mysql 레일을 사용하여 + 오전 : Btw는

@place = Place.new(params) 

을, 내 자리 테이블은 다음과 같이이다 :

`polygon` polygon DEFAULT NULL, 
`latlon` point DEFAULT NULL, 

그래서 처음에는 시도 rgeo가 폴리곤과 latlon을 텍스트에서 기하 도형으로 자동 변경하고 mysql을 매력적으로 저장하기를 희망한다. 그리고 그것은 포인트 유형으로 latlon에서 작동했습니다. 여기에 내가 불행하게도, 다각형 유형이 작동하지 않는

self.rgeo_factory_generator = RGeo::Geos.method(:factory) 
set_rgeo_factory_for_column(:latlon, RGeo::Geographic.spherical_factory) 
set_rgeo_factory_for_column(:polygon, RGeo::Geographic.spherical_factory) 

place.rb에 추가하는 것이다.

내가 rgeo에 발견/reographic/interface.rb

이 구현은 확인 고급

# geometric operations. In particular: 
    # 
    # * Relational operators such as Feature::Geometry#intersects? are 
    # not implemented for most types. 
    # * Relational constructors such as Feature::Geometry#union are 
    # not implemented for most types. 
    # * Buffer, convex hull, and envelope calculations are not 
    # implemented for most types. Boundaries are available except for 
    # GeometryCollection. 
    # * Length calculations are available, but areas are not. Distances 
    # are available only between points. 
    # * Equality and simplicity evaluation are implemented for some but 
    # not all types. 
    # * Assertions for polygons and multipolygons are not implemented. 

의 일부를 구현하지 않습니다. 그래서 나는 그것을 스스로해야한다. 나는 다음을 시도했지만 일하지 않았다.

polygon = RGeo::Geographic.spherical_factory.parse_wkt(params[:polygon]) 
params[:polygon] = polygon 
@place = Place.new(place_params) 
@place.save 

하지만 효과가있었습니다.

polygon = RGeo::Geographic.spherical_factory.parse_wkt(params[:polygon]) 
@place.polygon = polygon 
@place.save 

아마 ActiveRecord는 다른 유형과 다각형 객체를 동시에 처리 할 수 ​​없다고 생각합니다!