2013-03-18 29 views
5

私は、WKT形式で格納されたポリゴンを持つMySQLデータベースを使って作業しています。データベース内の多くのポリゴンに重複した点があります(たとえば、以下の例では、点-122.323502 47.600959が3回繰り返されます)。ポリゴンにエラーがあるときに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( "フラットアース"、ユークリッド)座標を意味します。あなたは地理座標( "曲線の地球"、楕円形)を渡しています。間違った工場を使用しています。 –

答えて

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]) 

作品を私のために!

@place = Place.new(params) 

ところで、私の場所の表は、このようなものです::

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

だから、最初に私が試した私は、このようなレールに場所レコードを作成しようとしたレール+が

ファーストをのmysql使用しています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

この実装はOK、より高度な

# 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のは、同時に他のタイプとポリゴンオブジェクトの両方を扱うことができないと思います!

関連する問題