我正在寻找一种方法来获取一个功能集为200个国家的现有ESRI Shapefile.每个国家/地区要素都具有"NAME"属性.我的目标是创建一个Python脚本,添加一个任意(现在)的附加属性,比如"POPULATION".
当然我安装了OSGeo和GeoDjango模块.我到目前为止:
from osgeo import ogr
infile = ogr.Open('sample.shp', 1) #'sample.shp' is a pre-existing ESRI shapefile described above
inlyr = infile.GetLayerByIndex(0)
Run Code Online (Sandbox Code Playgroud)
我错过了一个OGR函数,它允许我将Feature属性字段插入现有的Shapefile中吗?
在Ubuntu中运行这个非常短的脚本时接收段错误.
from osgeo import ogr, osr
shpfile = 'Census_County_TIGER00_IN.shp'
def cust_field(field):
'''cust_field(shpfile, field) creates a field definition, which, by calling cust_field(), can be used to create a field using the CreateField() function.
cust_field() DOES NOT create a field -- it simply creates a "model" for a field, that can then be called later. It's weird, but that's GDAL/OGR, as far as I can tell.'''
fieldDefn = ogr.FieldDefn(field, ogr.OFTInteger)
fieldDefn.SetWidth(14)
fieldDefn.SetPrecision(6)
return fieldDefn
ds = ogr.Open(shpfile, 1)
lyr = ds.GetLayerByIndex(0)
field …Run Code Online (Sandbox Code Playgroud) 我编写了一个函数,在单击某个元素时,将替换具有隐藏跨度的div.当我在标签中的"onclick ="attr中有事件处理程序时,该函数运行正常.但后来我试图"花哨"并用jQuery的.click()方法取代onclick attr.现在,当我尝试在页面上使用它时,只有一个笨蛋 - 没有任何反应.
但是,如果我在Chrome的js控制台中执行完全相同的代码,它的效果很好.这是我的js:
$("a#delete").click(function () {
$("a#delete").replaceWith($("span.hconf").attr("style", "none"))
});
Run Code Online (Sandbox Code Playgroud)
这是相关的html(在div里面,在外面):
<a class='modify' id="delete" u="{{ i.id }}" href='#'>delete</a>
<span class='hconf' style="display:none;">Are you sure? <a class='confirm' id='del_conf_true' onclick='deltrue();' href='#'>yes</a> | <a class='confirm' id='del_conf_false' href='#'>no</a></span>
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用"this"关键字更改第二个$("a#delete"),但我现在要撤消,因为我不确定这是否是问题的一部分.我是js/jQuery的新手.
我的页面有多个.click()事件,但只有第一个按预期执行.
$(function () {
$("#delete").click(function () {
$(this).hide();
$("span.hconf").show();
})
$("#div_conf_true").live("click", function () {
$.post("/u:" + $("span.username").text() + "/delete/"), {
url_id: $("#div_conf_true").attr("u"),
uname: $("span.username").text(),
complete: window.location.reload(true)
}
})
$("#div_conf_false").live("click", function () {
$("span.hconf").hide();
$("#delete").show();
})
})
Run Code Online (Sandbox Code Playgroud)
最初#div_conf_*事件是.click(function(){events,但我读到任何DOM更改都会取消绑定这些处理程序,所以我尝试了.live,但它仍然无效.我需要做什么才能做到这一点.脚本通过DOM更改可以访问所有三个点击事件?
我是jQuery的新手如此宽容,如果这有一个明显的答案.
编辑:第二个或第三个.click()事件都不起作用.我已经实现了响应者建议的语法和缩进更正,但仍然没有变化.上面的代码块是我脚本标记中的所有内容.我需要用其他东西包裹块吗?这是$ document.ready()的问题吗?我是否正确使用.live()?这是错误的方法选择吗?我在Chrome JS控制台中没有错误.
我主要担心的是,根据我的理解,第三个.click()函数应该简单地反转第一个.click()函数的效果,该函数按预期运行.我已粘贴下面的相关HTML.
<div id='modify'><a class='modify' id="edit" href='{{ edit_url }}'>edit</a> | <a class='modify' id="delete" u="{{ i.id }}" href='#'>delete</a><span class='hconf' style="display:none">Are you sure? <a class='confirm' id='del_conf_true' href='#'>yes</a> | <a class='confirm' id='del_conf_false' href='#'>no</a></span></div>
Run Code Online (Sandbox Code Playgroud)
Edit2:我更新了第二个.click()函数,但功能仍然没有变化.
$("#div_conf_true").live("click", function ( {
$.post("/u:"+$("span.username").text()+"/delete/",
{
url_id:$("#div_conf_true").attr("u"), …Run Code Online (Sandbox Code Playgroud)