我不知道这是我的代码中的某些交互,还是我使用的shapefile中的命名约定,但以下代码会生成Stack level too deep
消息
def read_shapefile
@shp_path = Dir[File.join( @tmp_path, '*.shp') ].first
srs_database = RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new
factory = RGeo::Geos.factory(:srs_database => srs_database, :srid => 96805)
#factory = RGeo::Geos::CAPIFactory.new
cartesian_preferred_factory = LandUnit.rgeo_factory_for_column(:location)
RGeo::Shapefile::Reader.open(@shp_path, factory: factory) do |file|
file.each do |record|
cartesian_cast = RGeo::Feature.cast(
record.geometry, factory: cartesian_preferred_factory, project: true)
cartesian_cast.each do |poly|
lu = LandUnit.new
lu.guid = record.attributes[@params['guid']].to_s
lu.country_code = @params['country_code']
lu.location = poly
# error happens here!
lu.save
end
end
end
end
模型迁移:
class CreateLandUnits < ActiveRecord::Migration
def change
create_table :land_units do |t|
t.string :country_code, null: false, index: true
t.string :guid, index: true
t.geometry :location, srid: 3785
t.timestamps
end
end
end
schema.rb的相关部分:
create_table "land_units", force: true do |t|
t.string "country_code", null: false
t.string "guid"
t.datetime "created_at"
t.datetime "updated_at"
t.spatial "location", limit: {:srid=>3785, :type=>"geometry"}
end
add_index "land_units", ["location"], :name => "index_land_units_on_location", :spatial => true
Backtrace指向active_record/transactions.rb
,第286行:
def rollback_active_record_state!
remember_transaction_record_state
yield
rescue Exception
restore_transaction_record_state
raise # HERE<<<
ensure
clear_transaction_record_state
end
尝试了一切。任何帮助将不胜感激。
编辑:如果有人想知道这些参数,那么在失败的电话中他们会解决这个问题:&#39; 6020048.00&#39;和country_code:&#39; ca&#39;。
我还应该补充一下,日志显示了这个:
(0.1ms) BEGIN
SQL (0.6ms) INSERT INTO "land_units" ("country_code", "created_at", "guid", "location", "updated_at")
VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["country_code", "ca"], ["created_at", "2015-03-23 20:59:38.771649"], ["guid", "6020048.00"],
["location", "002000000300000ec90000000100000028c164b311c749d0be4049101977159301c164b311c7508b1140491022249508cfc164b311c7671af24049103f70c23377c164b311c785400940491065d156a4f5c164b311c78493be40491082fd398873c164b311c783e2024049109c841e4650c164b311c78327ba404910ae43343896c164b311c7810e65404910b976a8c3dfc164b311c77c6113404910cf2943e8c7c164b311c777d3ba404910e3e11b1b56c164b311c771ff68404910fdcea7cc13c164b311c7716ef74049110061ae5237c164b311c76d520940491113afcec9eec164b311c7631bad4049114313691234c164b311c75f336f40491154764b6b38c164b311c75249bb40491140bebb55fac164b311c749492e40491135844d8b3fc164b311c740bbbb4049112ae8b30272c164b311c737d9274049111f6444e7acc164b311c72f4d334049111430f7e5f3c164b311c726871640491108fa115ffac164b311c71e34d2404910fe160b0597c164b311c7151806404910f28d86b4f4c164b311c70ca8b0404910e7a793a963c164b311c705b232404910deb9fc574ac164b311c703a91d404910dc20d4806ac164b311c6fb1d64404910d0ed325688c164b311c6f290ef404910c605069167c164b311c6e9e83a404910bacf71a130c164b311c6e0cba9404910af46584a4fc164b311c6f115694049105a80074a79c164b311c6f69ca64049103bc8277f0fc164b311c6facd224049102626e4a97cc164b311c6fec1f340491011192ee217c164b311c703ca8a40490ff67dac4e4ac164b311c707dc6d40490fe171e94d20c164b311c70c6bce40490fc98cc82ecdc164b311c720cc5340490fe45c78305ac164b311c73527f340490ffe8cde5378c164b311c749d0be4049101977159301"], ["updated_at", "2015-03-23 20:59:38.771649"
]]
(0.2ms) ROLLBACK
它显示的SQL在控制台中执行得很好!这是疯狂的一点。这告诉我,问题是一些before_save方法,但我还没有定义任何方法。
答案 0 :(得分:0)
我想我可能已经弄明白了。此空间参考代码“96805”在spatialreference.org上没有任何条目。我不是说它不存在,但它可能在其他一些srid下引用。
你可以追踪它,我想它存在但是使用其他一些代码引用。通常,在多个SRID引用下引用相同的proj4代码。无论如何,对于这个神秘投影文件的一个shapefile集,请在文本编辑器中打开*.prj
文件。这将显示您的proj4
代码。你可以从这里处理这种多种方式。有一件事是你可以将这个proj4代码复制到google中并尝试获取它的官方srid,然后从那里开始。
或者,您可以直接使用proj4代码重新制作几何图形,而无需任何正式的srid。