当我对多边形使用 update_attributes 时出现奇怪的更新

Weird update when I use update_attributes with polygons

我有一个 class 没有 attr_accessible,我们称它为 MyClass。 当我使用

MyClass.find(<id>).update_attributes(
  polygon1: MyPolygon1,
  polygon2: MyPolygon2
)

数据库中的新值是:

polygon1 = MyPolygon1 (OK)
polygon2 = '' (WRONG)

我们应该考虑 MyPolygon1 和 Mypoligon2 的值

MyPolygon1 = "POLYGON((-70.43399999999997 -33.480000000000004,-70.44400000000002 -33.485,-70.47199999999998 -33.475,-70.50799999999998 -33.436,-70.53899999999999 -33.429,-70.584 -33.432,-70.608 -33.416000000000004,-70.60500000000002 -33.409,-70.51600000000002 -33.372,-70.47699999999998 -33.364,-70.483 -33.377,-70.47699999999998 -33.393,-70.45400000000001 -33.397,-70.452 -33.417,-70.43399999999997 -33.428,-70.428 -33.458,-70.43399999999997 -33.480000000000004))"
MyPolygon2 = "POLYGON((-70.4337852 -33.48014739999999,-70.4344264 -33.481217,-70.43597139999999 -33.4822192,-70.4372588 -33.4837941,-70.438203 -33.4852258,-70.4388896 -33.4856554,-70.4404346 -33.4856554,-70.4442969 -33.4852258,-70.4472152 -33.484152099999996,-70.449361 -33.4830067,-70.4507342 -33.4825772,-70.45210749999998 -33.4817897,-70.4540816 -33.4805011,-70.4561416 -33.4792841,-70.4582873 -33.4778523,-70.460004 -33.476420399999995,-70.4615489 -33.4756329,-70.4646388 -33.4754181,-70.4672996 -33.4752033,-70.4694453 -33.4752749,-70.4710761 -33.4752033,-70.47244939999999 -33.4747022,-70.4742519 -33.4731987,-70.4764835 -33.4707644,-70.4779426 -33.4687597,-70.4800025 -33.46704129999999,-70.4822341 -33.4653229,-70.4841224 -33.463676,-70.4859715 -33.4628224,-70.4870873 -33.45945689999999,-70.48871809999999 -33.456521,-70.4906246 -33.4546496,-70.4916363 -33.4536566,-70.4939537 -33.4516515,-70.4955845 -33.450792099999994,-70.4949837 -33.4485004,-70.4949837 -33.4478201,-70.4952412 -33.4468891,-70.4961853 -33.445779,-70.4981165 -33.44427499999999,-70.4995327 -33.4429859,-70.5005627 -33.4416036,-70.5015068 -33.4405651,-70.5037814 -33.438573899999994,-70.5061417 -33.4368979,-70.5083304 -33.4358952,-70.5095063 -33.43569459999999,-70.51133449999999 -33.4354439,-70.5131798 -33.4353365,-70.5148964 -33.435085799999996,-70.5160981 -33.43467749999999,-70.5173855 -33.4341188,-70.519351 -33.4331017,-70.5199347 -33.4328439,-70.5205698 -33.4326505,-70.5215912 -33.4322708,-70.5222865 -33.4319342,-70.5229302 -33.431532999999995,-70.5236683 -33.4316118,-70.5284062 -33.4322064,-70.5324145 -33.4326863,-70.5378476 -33.4333739,-70.5379935 -33.4333453,-70.5381737 -33.433030099999996,-70.5385428 -33.432249299999995,-70.5388003 -33.4316333,-70.53898049999998 -33.4310388,-70.5390835 -33.4304729,-70.5391522 -33.4299214,-70.5391522 -33.4295202,-70.539135 -33.4291406,-70.5390749 -33.4288397,-70.5428772 -33.4292409,-70.54369229999999 -33.4293347,-70.5477953 -33.4298068,-70.5524731 -33.4303225,-70.5543442 -33.4305087,-70.5549365 -33.430515899999996,-70.5597001 -33.4307451,-70.5641718 -33.4309457,-70.5668326 -33.4310388,-70.5716048 -33.4311534,-70.5747977 -33.4312322,-70.5749437 -33.4312487,-70.5785321 -33.4313387,-70.5799219 -33.4314324,-70.5840099 -33.4316783,-70.5843619 -33.4317257,-70.5849457 -33.4311117,-70.5854493 -33.430558899999994,-70.5901718 -33.4266306,-70.5918111 -33.4253656,-70.5957971 -33.4222553,-70.5972526 -33.4211555,-70.5988645 -33.4200078,-70.5994001 -33.4196179,-70.5999784 -33.4191997,-70.601285 -33.4182304,-70.6018429 -33.41786509999999,-70.6020232 -33.4177758,-70.602418 -33.4176,-70.60331909999998 -33.4173492,-70.6038846 -33.4173091,-70.6041713 -33.4172815,-70.604426 -33.417239599999995,-70.6046198 -33.4171843,-70.6063353 -33.4163409,-70.6067451 -33.4163821,-70.6068366 -33.4163194,-70.6077289 -33.4160556,-70.60751569999998 -33.4155779,-70.6069498 -33.4142185,-70.6065979 -33.41286439999999,-70.606246 -33.4117969,-70.6053754 -33.4092325,-70.6046686 -33.4089918,-70.6041429 -33.4088227,-70.6036252 -33.4086548,-70.60287149999999 -33.4084107,-70.6025269 -33.4082999,-70.602256 -33.4082294,-70.6019985 -33.408181199999994,-70.6016498 -33.4081421,-70.6014178 -33.408132,-70.6010248 -33.4081186,-70.6004911 -33.40809839999999,-70.59995999999998 -33.4080816,-70.5993417 -33.4080626,-70.5991754 -33.4080547,-70.5989998 -33.4080391,-70.5987905 -33.408001,-70.5985827 -33.4079417,-70.5982876 -33.4078488,-70.597896 -33.4077189,-70.5976702 -33.407645,-70.5974449 -33.4075566,-70.5970184 -33.4073584,-70.5968213 -33.4072801,-70.59648999999999 -33.4071614,-70.5959603 -33.4069756,-70.5930407 -33.4059646,-70.5909781 -33.4052134,-70.5900956 -33.4049078,-70.5897443 -33.4048081,-70.5893969 -33.4047242,-70.58845009999999 -33.4045338,-70.58748319999998 -33.4043513,-70.5867093 -33.4042036,-70.5863334 -33.4041234,-70.5855228 -33.4038884,-70.5845014 -33.4034155,-70.5836378 -33.4029692,-70.5834125 -33.4028639,-70.5830759 -33.4027206,-70.5825113 -33.4024933,-70.5815108 -33.402072399999994,-70.5794616 -33.4012136,-70.5776069 -33.40042879999999,-70.5770235 -33.4001892,-70.5740999 -33.3990685,-70.57236179999998 -33.3983877,-70.5706182 -33.3977184,-70.5688179 -33.397047199999996,-70.5670349 -33.3964044,-70.5643742 -33.39549079999999,-70.56293349999999 -33.3949888,-70.5615125 -33.3945027,-70.5579711 -33.393276,-70.553774 -33.3917855,-70.5507459 -33.3906474,-70.5501613 -33.3904277,-70.5496046 -33.3902417,-70.5486252 -33.3898834,-70.5479851 -33.3896351,-70.54734 -33.38933839999999,-70.5467125 -33.3890859,-70.54584819999998 -33.38879769999999,-70.5446456 -33.3884011,-70.543967 -33.3881569,-70.5432924 -33.38788709999999,-70.5419569 -33.3873524,-70.5402182 -33.3866962,-70.5393623 -33.38634859999999,-70.5381871 -33.3858444,-70.5356208 -33.3847909,-70.5348569 -33.3844326,-70.5342389 -33.3840671,-70.5339042 -33.3837732,-70.53249659999999 -33.3823613,-70.5318564 -33.3817458,-70.5314249 -33.3813309,-70.5307971 -33.3807273,-70.529544 -33.3795303,-70.5283595 -33.3782187,-70.52720939999999 -33.3771293,-70.5255014 -33.37614729999999,-70.5203172 -33.3738752,-70.5176044 -33.3726576,-70.5160943 -33.3720617,-70.51267829999999 -33.3710152,-70.5113393 -33.370664,-70.5084897 -33.3702626,-70.5062839 -33.3700762,-70.5053912 -33.3699257,-70.5043355 -33.36949559999999,-70.4996918 -33.3673111,-70.4985245 -33.3669957,-70.4972545 -33.3669294,-70.4962331 -33.3669079,-70.4958211 -33.3668936,-70.4954778 -33.3668219,-70.4951945 -33.3666427,-70.4946195 -33.3659258,-70.4941989 -33.3653524,-70.4933921 -33.3648219,-70.4928857 -33.3645638,-70.49248229999999 -33.3644993,-70.4919158 -33.3644993,-70.49159819999998 -33.364449099999995,-70.4912635 -33.364384599999994,-70.4902164 -33.36440609999999,-70.48941809999998 -33.3644635,-70.4886714 -33.3646355,-70.4876329 -33.3646069,-70.486826 -33.364571,-70.4854871 -33.3644563,-70.4850751 -33.364356,-70.48456009999998 -33.36425559999999,-70.4842511 -33.3642484,-70.4839851 -33.3643416,-70.483822 -33.364449099999995,-70.48365029999998 -33.3646284,-70.4834701 -33.3647646,-70.4832727 -33.3648362,-70.4829723 -33.3648506,-70.4827319 -33.3648362,-70.4822942 -33.3646212,-70.4819337 -33.3644348,-70.4816075 -33.3643344,-70.4812728 -33.3643129,-70.4810325 -33.3642699,-70.4806119 -33.3641624,-70.479951 -33.3641839,-70.4794789 -33.3643058,-70.4789725 -33.3642771,-70.4776765 -33.3643129,-70.4766551 -33.3640549,-70.4766208 -33.3650656,-70.4766121 -33.3658392,-70.4765693 -33.3696461,-70.4777709 -33.3702196,-70.4798308 -33.3717249,-70.48094659999998 -33.3731226,-70.4816333 -33.3749503,-70.4825345 -33.376348,-70.4830066 -33.3772798,-70.4827491 -33.3784624,-70.4821054 -33.3805051,-70.4810325 -33.3819027,-70.4800454 -33.3830135,-70.4791442 -33.3840169,-70.4789725 -33.3850561,-70.4791871 -33.3859519,-70.4791442 -33.3868478,-70.4789725 -33.3879228,-70.4782859 -33.3892844,-70.4772988 -33.3903952,-70.4767409 -33.391076,-70.4765264 -33.3920076,-70.4765264 -33.3933333,-70.4761401 -33.393835,-70.47536769999999 -33.3941216,-70.4735072 -33.3943023,-70.4708035 -33.3940157,-70.4699452 -33.3938365,-70.4684861 -33.3943382,-70.4676429 -33.3948024,-70.4657975 -33.39512489999999,-70.4641238 -33.3949815,-70.4625789 -33.3949815,-70.4621926 -33.3950532,-70.4607335 -33.3957698,-70.4598752 -33.3960206,-70.4575578 -33.3964147,-70.4554978 -33.3969163,-70.45449569999998 -33.397097,-70.4538949 -33.3967029,-70.4539807 -33.3975628,-70.4532663 -33.3991735,-70.4526654 -33.4007141,-70.4520646 -33.4018964,-70.45215049999999 -33.40279209999999,-70.4525796 -33.4041893,-70.4528371 -33.4061239,-70.4532233 -33.4078077,-70.4533092 -33.4099929,-70.4532663 -33.4112468,-70.4529658 -33.415008099999994,-70.45232209999999 -33.417444,-70.4509059 -33.4191275,-70.4481164 -33.4213841,-70.4456273 -33.4233183,-70.4443828 -33.4242496,-70.4433957 -33.424643599999996,-70.4414216 -33.42493009999999,-70.4390184 -33.4250734,-70.4370443 -33.4255748,-70.4349414 -33.4265419,-70.43365389999998 -33.428082,-70.4333106 -33.4311622,-70.4325381 -33.43359749999999,-70.4314223 -33.4362477,-70.430564 -33.4379667,-70.4303924 -33.439256,-70.4308215 -33.44076,-70.4314223 -33.44247889999999,-70.4316798 -33.444341,-70.4311648 -33.445845,-70.4299632 -33.4469193,-70.4284183 -33.4484948,-70.4282466 -33.4503568,-70.4281608 -33.4522904,-70.4282466 -33.454581999999995,-70.4279033 -33.4563006,-70.4278175 -33.4581624,-70.4282466 -33.4600958,-70.4289332 -33.46210069999999,-70.430049 -33.4635328,-70.4312507 -33.4639624,-70.4324523 -33.463676,-70.43348229999998 -33.4638192,-70.4339114 -33.4646069,-70.4341689 -33.4664685,-70.4345981 -33.4680437,-70.4345122 -33.4691177,-70.4341689 -33.4703348,-70.43305309999998 -33.4719816,-70.4329673 -33.474988599999996,-70.4333106 -33.4772795,-70.4333106 -33.4793557,-70.4337852 -33.48014739999999,-70.4337852 -33.48014739999999))"

最后我可以添加一些我的数据库的相关信息。我使用 postgres 适配器,列的类型是 geometry(Polygon,4326).

我哪里不见了? ._.

poligon2 列的类型是什么? 也许您尝试保存的数据对于您的列类型而言太长(9k 个字符)。

终于找到错误了... 就在这里:

-70.4337852 -33.48014739999999,
-70.4337852 -33.48014739999999

我的多边形的最后两个点相同。 postgis 将该多边形保存为空白寄存器._.

非常感谢大家! :)