I'm working on openlayers 3 and ExtJS 6. I have a vector who is loaded with a GeoJson. I clear it and I want to add some new features once it's cleared.
My new data are provided by a store. So this is what I want to add in my vector :
[{"type":"Feature","properties":{"SCALERANK":6,"NATSCALE":30,"LABELRANK":5,"FEATURECLA":"Populated place","NAME":"Marsabit","NAMEPAR":null,"NAMEALT":null,"DIFFASCII":0,"NAMEASCII":"Marsabit","ADM0CAP":0,"CAPALT":0,"CAPIN":null,"WORLDCITY":0,"MEGACITY":0,"SOV0NAME":"Kenya","SOV_A3":"KEN","ADM0NAME":"Kenya","ADM0_A3":"KEN","ADM1NAME":"Eastern","ISO_A2":"KE","NOTE":null,"LATITUDE":2.329999,"LONGITUDE":37.979997,"CHANGED":1,"NAMEDIFF":0,"DIFFNOTE":"Changed scale rank.","POP_MAX":16460,"POP_MIN":15361,"POP_OTHER":16460,"RANK_MAX":6,"RANK_MIN":6,"GEONAMEID":187585,"MEGANAME":null,"LS_NAME":"Marsabit","LS_MATCH":1,"CHECKME":0,"MAX_POP10":16460,"MAX_POP20":16460,"MAX_POP50":0,"MAX_POP300":0,"MAX_POP310":0,"MAX_NATSCA":20,"MIN_AREAKM":12,"MAX_AREAKM":12,"MIN_AREAMI":5,"MAX_AREAMI":5,"MIN_PERKM":17,"MAX_PERKM":17,"MIN_PERMI":10,"MAX_PERMI":10,"MIN_BBXMIN":37.975,"MAX_BBXMIN":37.975,"MIN_BBXMAX":38.033333,"MAX_BBXMAX":38.033333,"MIN_BBYMIN":2.325,"MAX_BBYMIN":2.325,"MIN_BBYMAX":2.341667,"MAX_BBYMAX":2.341667,"MEAN_BBXC":38.004167,"MEAN_BBYC":2.333333,"COMPARE":0,"GN_ASCII":"Marsabit","FEATURE_CL":"P","FEATURE_CO":"PPL","ADMIN1_COD":3,"GN_POP":15361,"ELEVATION":0,"GTOPO30":1344,"TIMEZONE":"Africa/Nairobi","GEONAMESNO":"Geonames ascii name + lat.d + long.d matching.","UN_FID":0,"UN_ADM0":null,"UN_LAT":0,"UN_LONG":0,"POP1950":0,"POP1955":0,"POP1960":0,"POP1965":0,"POP1970":0,"POP1975":0,"POP1980":0,"POP1985":0,"POP1990":0,"POP1995":0,"POP2000":0,"POP2005":0,"POP2010":0,"POP2015":0,"POP2020":0,"POP2025":0,"POP2050":0,"CITYALT":null},"geometry":{"type":"Point","coordinates":[37.979996702838946,2.329998595077768]},"NAME":"Marsabit","id":"AIS_LIVE.model.PlacesModel-13153"},{"type":"Feature","properties":{"SCALERANK":7,"NATSCALE":20,"LABELRANK":3,"FEATURECLA":"Populated place","NAME":"Marsala","NAMEPAR":null,"NAMEALT":null,"DIFFASCII":0,"NAMEASCII":"Marsala","ADM0CAP":0,"CAPALT":0,"CAPIN":null,"WORLDCITY":0,"MEGACITY":0,"SOV0NAME":"Italy","SOV_A3":"ITA","ADM0NAME":"Italy","ADM0_A3":"ITA","ADM1NAME":"Sicily","ISO_A2":"IT","NOTE":null,"LATITUDE":37.805404,"LONGITUDE":12.438662,"CHANGED":0,"NAMEDIFF":0,"DIFFNOTE":null,"POP_MAX":77784,"POP_MIN":43179,"POP_OTHER":42587,"RANK_MAX":8,"RANK_MIN":7,"GEONAMEID":2524245,"MEGANAME":null,"LS_NAME":"Marsala","LS_MATCH":1,"CHECKME":0,"MAX_POP10":43179,"MAX_POP20":43179,"MAX_POP50":0,"MAX_POP300":0,"MAX_POP310":0,"MAX_NATSCA":20,"MIN_AREAKM":19,"MAX_AREAKM":19,"MIN_AREAMI":7,"MAX_AREAMI":7,"MIN_PERKM":25,"MAX_PERKM":25,"MIN_PERMI":16,"MAX_PERMI":16,"MIN_BBXMIN":12.425,"MAX_BBXMIN":12.425,"MIN_BBXMAX":12.491667,"MAX_BBXMAX":12.491667,"MIN_BBYMIN":37.766667,"MAX_BBYMIN":37.766667,"MIN_BBYMAX":37.816667,"MAX_BBYMAX":37.816667,"MEAN_BBXC":12.458631,"MEAN_BBYC":37.794643,"COMPARE":0,"GN_ASCII":"Marsala","FEATURE_CL":"P","FEATURE_CO":"PPL","ADMIN1_COD":15,"GN_POP":77784,"ELEVATION":0,"GTOPO30":7,"TIMEZONE":"Europe/Rome","GEONAMESNO":"Geonames ascii name + lat.d + long.d matching.","UN_FID":0,"UN_ADM0":null,"UN_LAT":0,"UN_LONG":0,"POP1950":0,"POP1955":0,"POP1960":0,"POP1965":0,"POP1970":0,"POP1975":0,"POP1980":0,"POP1985":0,"POP1990":0,"POP1995":0,"POP2000":0,"POP2005":0,"POP2010":0,"POP2015":0,"POP2020":0,"POP2025":0,"POP2050":0,"CITYALT":null},"geometry":{"type":"Point","coordinates":[12.43866166041903,37.805404275558374]},"NAME":"Marsala","id":"AIS_LIVE.model.PlacesModel-10722"},{"type":"Feature","properties":{"SCALERANK":4,"NATSCALE":50,"LABELRANK":3,"FEATURECLA":"Admin-1 region capital","NAME":"Marseille","NAMEPAR":null,"NAMEALT":"Marseille-Aix-en-Provence","DIFFASCII":0,"NAMEASCII":"Marseille","ADM0CAP":0,"CAPALT":0,"CAPIN":null,"WORLDCITY":0,"MEGACITY":1,"SOV0NAME":"French Republic","SOV_A3":"FRA","ADM0NAME":"France","ADM0_A3":"FRA","ADM1NAME":"Provence-Alpes-C-te-d'Azur","ISO_A2":"FR","NOTE":null,"LATITUDE":43.289979,"LONGITUDE":5.37501,"CHANGED":4,"NAMEDIFF":0,"DIFFNOTE":"Changed feature class.","POP_MAX":1400000,"POP_MIN":794811,"POP_OTHER":813666,"RANK_MAX":12,"RANK_MIN":11,"GEONAMEID":2995469,"MEGANAME":"Marseille-Aix-en-Provence","LS_NAME":"Marseille","LS_MATCH":1,"CHECKME":0,"MAX_POP10":946129,"MAX_POP20":1034294,"MAX_POP50":1034294,"MAX_POP300":0,"MAX_POP310":0,"MAX_NATSCA":50,"MIN_AREAKM":285,"MAX_AREAKM":361,"MIN_AREAMI":110,"MAX_AREAMI":140,"MIN_PERKM":237,"MAX_PERKM":327,"MIN_PERMI":147,"MAX_PERMI":203,"MIN_BBXMIN":5.158333,"MAX_BBXMIN":5.183333,"MIN_BBXMAX":5.633333,"MAX_BBXMAX":5.633333,"MIN_BBYMIN":43.216667,"MAX_BBYMIN":43.216667,"MIN_BBYMAX":43.466123,"MAX_BBYMAX":43.525,"MEAN_BBXC":5.397504,"MEAN_BBYC":43.351337,"COMPARE":0,"GN_ASCII":"Marseille","FEATURE_CL":"P","FEATURE_CO":"PPLA","ADMIN1_COD":0,"GN_POP":794811,"ELEVATION":0,"GTOPO30":54,"TIMEZONE":"Europe/Paris","GEONAMESNO":"Geonames ascii name + lat.d + long.d matching.","UN_FID":187,"UN_ADM0":"France","UN_LAT":43.28,"UN_LONG":5.38,"POP1950":756,"POP1955":798,"POP1960":929,"POP1965":1069,"POP1970":1182,"POP1975":1253,"POP1980":1295,"POP1985":1307,"POP1990":1305,"POP1995":1331,"POP2000":1357,"POP2005":1386,"POP2010":1400,"POP2015":1418,"POP2020":1445,"POP2025":1469,"POP2050":1490,"CITYALT":"Marseille"},"geometry":{"type":"Point","coordinates":[5.37306427182989,43.29192492260455]},"NAME":"Marseille","id":"AIS_LIVE.model.PlacesModel-13925"}]
But if I execute: me.getData('myVector').getSource().addFeatures(myData)
I've got an error.
I also tried
var format = new ol.format.GeoJSON();
me.getData('myVector').addFeatures(format.readFeatures( myData, {
featureProjection: 'EPSG:3857'
} ) );
It gives me 0 error but I when I want to display all my features there is nothing in my vector.
How can I do?
I've run into an issue with the TabularAdapter in the TraitsUI package...
I've been trying to figure this out on my own for much too long now, so I wanted to ask the experts here for some friendly advise :)
I'm going to add a piece of my program that illustrates my problem(s), and I'm hoping someone can look it over and say 'Ah Ha!...Here's your problem' (my fingers are crossed).
Basically, I can use the TabularAdapter to produce a table editor into an array of dtypes, and it works just fine except:
1) whenever I change the # of elements (identified as 'Number of fractures:'), the array gets resized, but the table doesn't reflect the change until after I click on one of the elements. What I'd like to happen is that the # of rows (fractures) changes after I release the # of fractures slider. Is this doable?
2) The second issue I have is that if the array gets resized before it's displayed by .configure_traits() (by the notifier when Number_of_fractures gets modified), I can shrink the size of the array, but I can't increase it over the new size.
2b) I thought I'd found a way to have the table editor display the full array even when it's increased over the 5 set in the code (just before calling .trait_configure()), but I was fooled :( I tried adding another Group() in front of the vertical_fracture_group so the table wasn't the first thing to display. This more closely emulates my entire program. When I did this, I was locked into the new smaller size of the array, and I could no longer increase its size to my maximum of 15. I'm modifying the code to reflect this issue.
Here's my sample code:
# -*- coding: utf-8 -*-
"""
This is a first shot at developing a ****** User Interface using Canopy by
Enthought. Canopy is a distribution of the Python language which has a lot of
scientific and engineering features 'built-in'.
"""
#-- Imports --------------------------------------------------------------------
from traitsui.api import TabularEditor
from traitsui.tabular_adapter import TabularAdapter
from numpy import zeros, dtype
from traits.api import HasTraits, Range
from traitsui.api import View, Group, Item
#-- FileDialogDemo Class -------------------------------------------------------
max_cracks = 15 #maximum number of Fracs/cracks to allow
class VertFractureAdapter(TabularAdapter):
columns = [('Frac #',0), ('X Cen',1), ('Y Cen',2), ('Z Cen',3),
('Horiz',4), ('Vert',5), ('Angle',6)]
class SetupDialog ( HasTraits ):
Number_Of_Fractures = Range(1, max_cracks) # line 277
vertical_frac_dtype = dtype([('Fracture', 'int'), ('x', 'float'), ('y', 'float'),
('z', 'float'), ('Horiz Length', 'float'), ('Vert Length', 'float')
, ('z-axis Rotation, degrees', 'float')])
vertical_frac_array = zeros((max_cracks), dtype=vertical_frac_dtype)
vertical_fracture_group = Group(
Item(name = 'vertical_frac_array',
show_label = False,
editor = TabularEditor(adapter = VertFractureAdapter()),
width = 0.5,
height = 0.5,
)
)
#-- THIS is the actual 'View' that gets put on the screen
view = View(
#Note: When as this group 'displays' before the one with the Table, I'm 'locked' into my new maximum table display size of 8 (not my original/desired maximum of 15)
Group(
Item( name = 'Number_Of_Fractures'),
),
#Note: If I place this Group() first, my table is free to grow to it's maximum of 15
Group(
Item( name = 'Number_Of_Fractures'),
vertical_fracture_group,
),
width = 0.60,
height = 0.50,
title = '****** Setup',
resizable=True,
)
#-- Traits Event Handlers --------------------------------------------------
def _Number_Of_Fractures_changed(self):
""" Handles resizing arrays if/when the number of Fractures is changed"""
print "I've changed the # of Fractures to " + repr(self.Number_Of_Fractures)
#if not self.user_StartingUp:
self.vertical_frac_array.resize(self.Number_Of_Fractures, refcheck=False)
for crk in range(self.Number_Of_Fractures):
self.vertical_frac_array[crk]['Fracture'] = crk+1
self.vertical_frac_array[crk]['x'] = crk
self.vertical_frac_array[crk]['y'] = crk
self.vertical_frac_array[crk]['z'] = crk
# Run the program (if invoked from the command line):
if __name__ == '__main__':
# Create the dialog:
fileDialog = SetupDialog()
fileDialog.configure_traits()
fileDialog.Number_Of_Fractures = 8
In my discussion with Chris below, he made some suggestions that so far haven't worked for me :( Following is my 'current' version of this test code so Chris (or anyone else who wishes to chime in) can see if I'm making some glaring error.
# -*- coding: utf-8 -*-
"""
This is a first shot at developing a ****** User Interface using Canopy by
Enthought. Canopy is a distribution of the Python language which has a lot of
scientific and engineering features 'built-in'.
"""
#-- Imports --------------------------------------------------------------------
from traitsui.api import TabularEditor
from traitsui.tabular_adapter import TabularAdapter
from numpy import zeros, dtype
from traits.api import HasTraits, Range, Array, List
from traitsui.api import View, Group, Item
#-- FileDialogDemo Class -------------------------------------------------------
max_cracks = 15 #maximum number of Fracs/cracks to allow
class VertFractureAdapter(TabularAdapter):
columns = [('Frac #',0), ('X Cen',1), ('Y Cen',2), ('Z Cen',3),
('Horiz',4), ('Vert',5), ('Angle',6)]
even_bg_color = 0xf4f4f4 # very light gray
class SetupDialog ( HasTraits ):
Number_Of_Fractures = Range(1, max_cracks) # line 277
dummy = Range(1, max_cracks)
vertical_frac_dtype = dtype([('Fracture', 'int'), ('x', 'float'), ('y', 'float'),
('z', 'float'), ('Horiz Length', 'float'), ('Vert Length', 'float')
, ('z-axis Rotation, degrees', 'float')])
vertical_frac_array = Array(dtype=vertical_frac_dtype)
vertical_fracture_group = Group(
Item(name = 'vertical_frac_array',
show_label = False,
editor = TabularEditor(adapter = VertFractureAdapter()),
width = 0.5,
height = 0.5,
)
)
#-- THIS is the actual 'View' that gets put on the screen
view = View(
Group(
Item( name = 'dummy'),
),
Group(
Item( name = 'Number_Of_Fractures'),
vertical_fracture_group,
),
width = 0.60,
height = 0.50,
title = '****** Setup',
resizable=True,
)
#-- Traits Event Handlers --------------------------------------------------
def _Number_Of_Fractures_changed(self, old, new):
""" Handles resizing arrays if/when the number of Fractures is changed"""
print "I've changed the # of Fractures to " + repr(self.Number_Of_Fractures)
vfa = self.vertical_frac_array
vfa.resize(self.Number_Of_Fractures, refcheck=False)
for crk in range(self.Number_Of_Fractures):
vfa[crk]['Fracture'] = crk+1
vfa[crk]['x'] = crk
vfa[crk]['y'] = crk
vfa[crk]['z'] = crk
self.vertical_frac_array = vfa
# Run the program (if invoked from the command line):
if __name__ == '__main__':
# Create the dialog:
fileDialog = SetupDialog()
# put the actual dialog up...if I put it up 'first' and then resize the array, I seem to get my full range back :)
fileDialog.configure_traits()
#fileDialog.Number_Of_Fractures = 8
There are two details of the code that are causing the problems you describe. First, vertical_frac_array is not a trait, so the tabular editor cannot monitor it for changes. Hence, the table only refreshes when you manually interact with it. Second, traits does not monitor the contents of an array for changes, but rather the identity of the array. So, resizing and assigning values into the array will not be detected.
One way to fix this is to first make vertical_frac_array and Array trait. E.g. vertical_frac_array = Array(dtype=vertical_frac_dtype). Then, inside of _Number_Of_Fractures_changed, do not resize the vertical_frac_array and modify it in-place. Instead, copy vertical_frac_array, resize it, modify the contents, and then reassign the manipulated copy back to vertical_frac_array. This way the table will see that the identity of the array has changed and will refresh the view.
Another option is to make vertical_frac_array a List instead of an Array. This avoids the copy-and-reassign trick above because traits does monitor the content of lists.
Edit
My solution is below. Instead of resizing the vertical_frac_array whenever Number_Of_Fractures changes, I instead recreate the array. I also provide a default value for vertical_frac_array via the _vertical_frac_array_default method. (I removed from unnecessary code in the view as well.)
# -*- coding: utf-8 -*-
"""
This is a first shot at developing a ****** User Interface using Canopy by
Enthought. Canopy is a distribution of the Python language which has a lot of
scientific and engineering features 'built-in'.
"""
#-- Imports --------------------------------------------------------------------
from traitsui.api import TabularEditor
from traitsui.tabular_adapter import TabularAdapter
from numpy import dtype, zeros
from traits.api import HasTraits, Range, Array
from traitsui.api import View, Item
#-- FileDialogDemo Class -------------------------------------------------------
max_cracks = 15 #maximum number of Fracs/cracks to allow
vertical_frac_dtype = dtype([('Fracture', 'int'), ('x', 'float'), ('y', 'float'),
('z', 'float'), ('Horiz Length', 'float'), ('Vert Length', 'float')
, ('z-axis Rotation, degrees', 'float')])
class VertFractureAdapter(TabularAdapter):
columns = [('Frac #',0), ('X Cen',1), ('Y Cen',2), ('Z Cen',3),
('Horiz',4), ('Vert',5), ('Angle',6)]
class SetupDialog ( HasTraits ):
Number_Of_Fractures = Range(1, max_cracks) # line 277
vertical_frac_array = Array(dtype=vertical_frac_dtype)
view = View(
Item('Number_Of_Fractures'),
Item(
'vertical_frac_array',
show_label=False,
editor=TabularEditor(
adapter=VertFractureAdapter(),
),
width=0.5,
height=0.5,
),
width=0.60,
height=0.50,
title='****** Setup',
resizable=True,
)
#-- Traits Defaults -------------------------------------------------------
def _vertical_frac_array_default(self):
""" Creates the default value of the `vertical_frac_array`. """
return self._calculate_frac_array()
#-- Traits Event Handlers -------------------------------------------------
def _Number_Of_Fractures_changed(self):
""" Update `vertical_frac_array` when `Number_Of_Fractures` changes """
print "I've changed the # of Fractures to " + repr(self.Number_Of_Fractures)
#if not self.user_StartingUp:
self.vertical_frac_array = self._calculate_frac_array()
#-- Private Interface -----------------------------------------------------
def _calculate_frac_array(self):
arr = zeros(self.Number_Of_Fractures, dtype=vertical_frac_dtype)
for crk in range(self.Number_Of_Fractures):
arr[crk]['Fracture'] = crk+1
arr[crk]['x'] = crk
arr[crk]['y'] = crk
arr[crk]['z'] = crk
return arr
# Run the program (if invoked from the command line):
if __name__ == '__main__':
# Create the dialog:
fileDialog = SetupDialog()
fileDialog.configure_traits()
The problem is as follows
I want to read a video file from disk and convert its every frame into grayscale and write it into new video file
I am using following code to do so
CvCapture* capture = cvCreateFileCapture( "/root/tree.avi");
if (!capture){
return -1;
}
...
CvVideoWriter* writer =
cvCreateVideoWriter("/root/output.avi",CV_FOURCC('D','I','V','X'),fps,size);
...
IplImage* gray_frame = cvCreateImage(
size,
IPL_DEPTH_8U,
1
);
while( (bgr_frame=cvQueryFrame(capture)) != NULL ) {
cvShowImage( "Example2_10", bgr_frame );
cvCvtColor(bgr_frame,gray_frame,CV_RGB2GRAY);
cvShowImage( "B&W result", gray_frame );
cvWriteFrame( writer, gray_frame);
char c = cvWaitKey(10);
if( c == 27 ) break;
}
...
The problem is , program runs fine , but fails to write frames to output.avi and creats only blank output.avi file of just 5.5KB
One more thing is i am unable to write only gra_frame using cvWriteFrame , and if i try to Write bgr_frame , it does write the output.avi file successfully.
Please if anyone knows solution, let me know
You need to pass is_color=0 to the cvCreateVideoWriter function if you want to write gray value images. Because of that you are only able to write color images to your output video.
It is the last parameter of the cvCreateVideoWriter function which defaults to 1:
CvVideoWriter* cvCreateVideoWriter(const char* filename, int fourcc, double fps, CvSize frame_size, int is_color=1)
In my case the problem was that I created an a CvVideoWriter in a different resolution than the image I wrote to it using cvWriteFrame. This worked fine in an earlier version of OpenCV, but failed to write frames in OpenCV 2.4