Re: [Qgis-developer] Labeling: data-defined fields shifted after new vector API?

2013-02-05 Thread Larry Shaffer
Hi,

martin Dobias wrote:
>

>
The source of the problem is that before, it was possible to have
> "holes" in attribute field indices: e.g. three attributes with indices
> 0,2,3. Whether such holes appeared depended on the provider being
> used. The support for holes has been removed for performance and
> simplicity - many developers were not even aware of this thing.
>
> As a quick fix I think you'll need to update your project file. The
> proper fix should change writing of attributes as names in
> data-defined properties (for new labeling).
>

Ok, I've looked into fixing this (and have a couple of ideas), but need a
clarification first:

Is mFields[i].originIndex (where mFields is a QgsFields vector) the same
index used for the keys in QgsFieldMap?

In other words, will this new method, QgsFields::toQgsFieldMap(), function
correctly [0]? If so, I can use it to attempt to auto-convert
QgsFieldMap-index-based data defined properties over to field-name-based
properties, without having think about reintroducing any QgsFieldMap
functionality at the provider level.

If adding that method is a reasonable approach, do I need to filter the
added fields in any way (e.g. by FieldOrigin)?

[0] http://drive.dakotacarto.com/qgis/qgsfields-qgsfieldmap_patch.diff

Regards,

Larry
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] How to get Provider default values for each attribute using Python

2013-02-05 Thread vinayan
Hi Alexandre,

I recently used provider default values in a plugin like this..

provider = layer.dataProvider()
f = QgsFeature()

#On the Fly reprojection.
if layerCRSSrsid != projectCRSSrsid:
geom.transform(QgsCoordinateTransform(projectCRSSrsid,
layerCRSSrsid))

f.setGeometry(geom)

# add attribute fields to feature
fields = layer.pendingFields()

# vector api change update
if QGis.QGIS_VERSION_INT >= 10900:
f.initAttributes(fields.count())
for i in range(fields.count()):
f.setAttribute(i,provider.defaultValue(i))
else:
for i in fields:
f.addAttribute(i,  provider.defaultValue(i))



--
View this message in context: 
http://osgeo-org.1560.n6.nabble.com/How-to-get-Provider-default-values-for-each-attribute-using-Python-tp5032168p5032343.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[Qgis-developer] Plugin update on a plugin I don't own

2013-02-05 Thread Olivier Dalang
Hi !

I've been doing some work on the Improved Polygon Capturing plugin. It now
allows to enter the angle numerically also (along with some other
enhancements).

I've contacted the original author who seemed enthusiast about the changes,
but now I've got no news of him since about one month... So it seems he's
not actively maintaining the plugin anymore.

I asked on the IRC what to do, they said it is possible to transfer the
plugin ownership.
- Can someone do that ?
- Do you think it's rude to the original author ? (since I haven't got his
clear agreement)
- How/where should I leave his name as the original author ? (is it
possible to have 2 authors in the metadata?)

Here's the plugin repo :
https://github.com/olivierdalang/improvedpolygoncapturing

Best regards,

Olivier
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[Qgis-developer] MapBox access

2013-02-05 Thread Jody Garnett
Quick question about the support for tiled servers in QGIS. 

My first question is if data published by map box is available for use in QGIS 
(not sure if this is permissible under the license they provide, the website 
tends to talk only about javascript access).

And the second one is how you sorted out the license side of the equation for 
google maps access, do users fill in a google id or something? 

-- 
Jody Garnett

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] new vector api select features

2013-02-05 Thread Martin Dobias
Hi Richard

On Tue, Feb 5, 2013 at 7:27 PM, Richard Duivenvoorde
 wrote:
> Hi Devs,
>
> I used the following in a python plugin to select features:
>
> self.provider.select(self.provider.attributeIndexes(), mapCanvasExtent,
> True, True)
>
> is there somewhere an example how to do this in the new api using
>
> QgsFeatureIterator QgsOgrProvider::getFeatures( const QgsFeatureRequest&
> request )
>
> and python?

I haven't updated the examples yet, sorry. Here we go in Python:

for f in layer.getFeatures():
  print f["name"].toString(), f.geometry().exportToWkt()

This will use give you all features from a layer with geometries and
attributes. If no request is specified in the getFeatures() call, it
will use default request which fetches everything - equal to calling
getFeatures(QgsFeatureRequest()).

The getFeatures() call returns QgsFeatureIterator instance. Python
bindings of this class support python's iterator protocol [1] so you
can use it directly in a 'for' cycle as shown above. Of course it is
still possible to original C++ API style, but it does not feel very
pythonic:

f = QgsFeature()
iter = layer.getFeatures()
while iter.nextFeature(f):
  print f["name"].toString(), f.geometry().exportToWkt()

I strongly recommend the former variant - it's easier to write and
understand, so less prone to errors.

Access to attributes: there is no f.attributeMap() anymore, because
attributes are now stored in a vector (Python: list) instead of a map
(Python: dict). QgsFeature class emulates python container object [2]
so you can access attributes as if QgsFeature instance was a list or
dictionary, with keys being either field indices or field names:
f[0]  ... first attribute
f["type"]  ... attribute named "type"
It is still possible to get all attributes: f.attributes() returns a
list of values.

Attribute values are returned as QVariant's as before, so in order to
access a string attribute you need to do something like
f["name"].toString(), for integers it is the cryptic
f["speed"].toInt()[0]. At some point (before the release of 2.0) I
would like to switch QGIS to use newer PyQt4 API that does automatic
conversion of QVariant to python objects. This will cause that
f["name"] or f["speed"] will directly return a string or int without
the need to call toString()/toInt() methods).

Currently we have three types of requests: 1. no filter (default), 2.
filter by rectangle, 3. filter by feature ID.

Fetching of features within a rectangle is done this way:
rect = QgsRectangle(-10,-10,10,10)
request = QgsFeatureRequest().setFilterRect(rect)
for f in layer.getFeatures(request):
  # usual stuff here with the feature

For the sake of processing speed, some providers may return features
that are not in the rectangle (only their bounding box intersects the
rectangle). Usually this is not a problem (e.g. for rendering), but
for some cases such as identification of features in particular
rectangle this is not wanted. In old API, setting fourth argument of
select() to true returned only features that really intersected the
rectangle. In new API this is done with a flag:
request.setFlags(QgsFeatureRequest.ExactIntersect)

Another type of requests are requests for a particular feature ID. In
these cases we expect just one feature so we could directly fetch just
one feature from the iterator:
request = QgsFeatureRequest().setFilterFid(14)
f = l.getFeatures(request).next()

In case feature with given ID does not exist, python exception
StopIteration is raised.

If developers would like to optimize the requests to avoid fetching
things that are not required, it is possible to:
- avoid fetching of geometry: request.setFlags(QgsFeatureRequest.NoGeometry)
- fetch only some (or no) attributes - e.g. fetch just first two
attributes: request.setSubsetOfAttributes([0,1])

Even though API allows that, it is currently not possible to have
concurrent feature iterators on one layer or data provider, something
like this:
iter1 = layer.getFeatures()
iter2. = layer.getFeatures()
# do something with both iter1 and iter2
This will NOT work - in the second getFeatures() call the iter1 will
get closed and it will not return any more features. In the future
some providers will support concurrent iterators, there will be
probably another provider capability that would determine if a
provider supports that.

I hope I haven't forgotten any important use case. If more examples
are necessary, I will try to provide them. Please do not hesitate to
ask if things are not clear yet.

Regards
Martin

[1] http://docs.python.org/2/library/stdtypes.html#generator-types
[2] http://docs.python.org/2/reference/datamodel.html#object.__getitem__
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[Qgis-developer] new vector api select features

2013-02-05 Thread Richard Duivenvoorde

Hi Devs,

I used the following in a python plugin to select features:

self.provider.select(self.provider.attributeIndexes(), mapCanvasExtent, 
True, True)


is there somewhere an example how to do this in the new api using

QgsFeatureIterator QgsOgrProvider::getFeatures( const QgsFeatureRequest& 
request )


and python?

If provided, I could add the info at: 
http://documentation.qgis.org/html/en/docs/pyqgis_developer_cookbook/03_vector.html#iterating-over-vector-layer


(or maybe someone can update that pages instead of replying :-) )

Regards,

Richard Duivenvoorde
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] big ECW problem

2013-02-05 Thread Régis Haubourg
Hi Sylvain, 
I have no problem with 92 Go ecw... 1.8 is sometimes a bit slower than
1.7.4, it' true.. Did you play with stretching options?
Régis



--
View this message in context: 
http://osgeo-org.1560.n6.nabble.com/big-ECW-problem-tp5032161p5032241.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] include matplotlib in win standalone installer

2013-02-05 Thread Josef K
Thank you Jürgen!

From: "Jürgen E." Fischer 
> To: qgis-developer@lists.osgeo.org
> Date: Tue, 5 Feb 2013 14:57:55 +0100
> Subject: Re: [Qgis-developer] include matplotlib in win standalone
> installer
> Hi Josef K,
>
> On Tue, 05. Feb 2013 at 14:23:08 +0100, Josef K wrote:
> >How can I include matplotlib in a qgis-master standalone installer for
> >windows using the procedure described here:
> >[1]
> http://linfiniti.com/2012/05/quick-tip-build-the-latest-qgis-nightly-build-as-a-standalone-installer-for-windows/
>
> Just add the packages:
>
> ./creatensis.pl qgis-dev matplotlib
>
>
> Jürgen
>

That was almost embarrasingly simple :)
/Josef
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] include matplotlib in win standalone installer

2013-02-05 Thread Jürgen E . Fischer
Hi Josef K,

On Tue, 05. Feb 2013 at 14:23:08 +0100, Josef K wrote:
>How can I include matplotlib in a qgis-master standalone installer for
>windows using the procedure described here:
>
> [1]http://linfiniti.com/2012/05/quick-tip-build-the-latest-qgis-nightly-build-as-a-standalone-installer-for-windows/

Just add the packages:

./creatensis.pl qgis-dev matplotlib


Jürgen

-- 
Jürgen E. Fischer norBIT GmbH   Tel. +49-4931-918175-31
Dipl.-Inf. (FH)   Rheinstraße 13Fax. +49-4931-918175-50
Software Engineer D-26506 Norden   http://www.norbit.de
committ(ed|ing) to Quantum GIS IRC: jef on FreeNode 


-- 
norBIT Gesellschaft fuer Unternehmensberatung und Informationssysteme mbH
Rheinstrasse 13, 26506 Norden
GF: Jelto Buurman, HR: Amtsgericht Emden, HRB 5502

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[Qgis-developer] include matplotlib in win standalone installer

2013-02-05 Thread Josef K
How can I include matplotlib in a qgis-master standalone installer for
windows using the procedure described here:
http://linfiniti.com/2012/05/quick-tip-build-the-latest-qgis-nightly-build-as-a-standalone-installer-for-windows/

thanks in advance,
Josef
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[Qgis-developer] How to get Provider default values for each attribute using Python

2013-02-05 Thread Alexandre Neto
I'm not sure if this is the right place to put this kind of questions, has
all I see in here are much more complex debates about the actual
developping of QGIS.

I'm not very proficient neither with Python or QGIS API, but i'm trying to
create a plugin that allows one to transform a selected multipart feature
into singlepart features while editing in
QGIS?,
a very simple but useful tool while editing.

So far I manage to create the code that works with regular shapefiles, you
can see it at the end of the email.

My problem now is to make it work with Postgis layers due to the unique
values sequences. I toke a look into
QgsVectorLayer::splitFeatures
for
inspiration, has the objective is mostly the same, but I'm not being able
to correctly translate the code to Python that checks for a provider and
when possible replace the original attribute by the providers defaultValue

02412 //use default value where possible (primary key issue),
otherwise the value from the original (splitted) feature02413
QgsAttributeMap

newAttributes = select_it->attributeMap();02414 QVariant
defaultValue;02415 for ( int j = 0; j < newAttributes.size();
++j )02416 {02417   if ( mDataProvider

)02418   {02419 defaultValue = mDataProvider
->defaultValue
(
j );02420 if ( !defaultValue.isNull() )02421
{02422   newAttributes.insert( j, defaultValue );02423
}02424   }02425 }


I'm not being able to check for mDataProvider or getting the
mDataProvider.defaultValue(j). So far I could get to "see" the attribute
default value with the code below but I'm not sure what to do with it.

layer.dataProvider().defaultValue(0)





Thanks for the help,

Alexandre Neto



My actual plugin code is this:



layer = self.iface.mapCanvas().currentLayer()
new_features = []
n_of_splitted_features = 0
n_of_new_features = 0

for feature in layer.selectedFeatures():
geom = feature.geometry()
# if feature geometry is multipart starts split processing
if geom.isMultipart():
n_of_splitted_features += 1
#remove_list.append(feature.id())

# Get attributes from original feature
new_attributes = feature.attributeMap() ### Change to work with
Postgis

# Get parts from original feature
parts = geom.asGeometryCollection ()

# from 2nd to last part create a new features using their
# single geometry and the attributes of the original feature
temp_feature = QgsFeature()
temp_feature.setAttributeMap(new_attributes)
for i in range(1,len(parts)):
temp_feature.setGeometry(parts[i])
new_features.append(QgsFeature(temp_feature))
# update feature geometry to hold first part single geometry
# (this way one of the output feature keeps the original Id)
feature.setGeometry(parts[0])
layer.updateFeature(feature)

# add new features to layer
n_of_new_features = len(new_features)
if n_of_new_features > 0:
layer.addFeatures(new_features, False)

print ("Splited " + str(n_of_splitted_features) + " feature(s) into " +
str(n_of_new_features + n_of_splitted_features) + " new ones.")


___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[Qgis-developer] big ECW problem

2013-02-05 Thread PIERRE Sylvain
Hi,

I'm trying to load a big ecw (36 go)  into Qgis (1.8)
The file is loading but canvas doesn't display anything (still white)

A french user told me having similar problems with ecw files larger than 4 Go 
still QGis 1.7 release

He has solved these problem with downloading erdas sdk ecw and replacing QGis 
vc80 dll's by those resulting  from erdas sdk.

Does anybody know anything about these problems and proposed solution?
Thanks

Sylvain
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer