Python Rasterize Sum Variableconvert vector (point shape) to raster (tif) using python gdal lib in...

Why do neural networks need so many examples to perform?

Does the ditching switch allow an A320 to float indefinitely?

Boss asked me to sign a resignation paper without a date on it along with my new contract

Word for something that's always reliable, but never the best?

How to write cases in LaTeX?

What is the industry term for house wiring diagrams?

How to deal with an underperforming subordinate?

Illustrator to chemdraw

Can my friend and I spend the summer in Canada (6 weeks) at 16 years old without an adult?

Is there any danger of my neighbor having my wife's signature?

If angels and devils are the same species, why would their mortal offspring appear physically different?

Need help with a circuit diagram where the motor does not seem to have any connection to ground. Error with diagram? Or am i missing something?

Writing dialogues for characters whose first language is not English

Can a player sacrifice a creature after declaring that creature as blocker while taking lethal damage?

Potential client has a problematic employee I can't work with

Why did Ylvis use "go" instead of "say" in phrases like "Dog goes 'woof'"?

Count repetitions of an array

Single-row INSERT...SELECT much slower than separate SELECT

Article. The word "Respect"

Critique vs nitpicking

Memory usage: #define vs. static const for uint8_t

A question about partitioning positivie integers into finitely many arithmetic progresions

I have trouble understanding this fallacy: "If A, then B. Therefore if not-B, then not-A."

How to not let the Identify spell spoil everything?



Python Rasterize Sum Variable


convert vector (point shape) to raster (tif) using python gdal lib in qgisRasterize vector file using gdal.RasterizeLayer() without losing attribute information in pythonRasterize (R package raster) fails to rasterize island polygons?Different output from rasterizeProblem Rasterize QGISRasterize (Vector to raster) ERROR 6Rasterize stuck in QGISRasterize Vector MultiLineRasterio write_band output has no CRSRasterize a shapefile generate a black TIFF













0















I'm trying to reproduce the R rasterize function in python to streamline my code and am having issues with summing multiple points in the raster. Essentially I want to sum the value of my variable for every point in the grid I create. However currently it only appears to be returning the value of the first point in the grid it sees.



import rasterio
import geopandas as gpd

def create_raster_defined_res(geodataset, output, out_var, resolution):
res = (resolution, resolution)
bounds = geodataset.total_bounds
kwargs = {
'count': 1,
'crs': geodataset.crs['init'],
'bounds': bounds,
'width': max(int(ceil((bounds[2] - bounds[0]) / float(res[0]))), 1),
'height': max(int(ceil((bounds[3] - bounds[1]) / float(res[1]))), 1),
'affine': Affine(res[0], 0, bounds[0], 0, -res[1], bounds[3]),
'transform': (bounds[0], res[0], 0, bounds[3], 0, -res[1]),
'compress': 'lzw',
'driver': u'GTiff',
'dtype': 'float64',
#'nodata': -1e+308
}

with rasterio.open(output, 'w', **kwargs) as out:
out_arr = np.empty([kwargs['height'],kwargs['width']])

# this is where we create a generator of geom, value pairs to use in rasterizing
shapes = ((geom,value) for geom, value in zip(geodataset['geometry'], geodataset[out_var]))

burned = rasterize(shapes=shapes, fill=0, out=out_arr, transform=kwargs['affine'])
out.write_band(1, burned)

create_raster_defined_res(geopandas_dataset, output_tiff, output_var, 2500)


Is there a way to add a parameter to sum the value of all the points that enter into the grid or tell it to add instead of just taking the value of the first point?










share|improve this question



























    0















    I'm trying to reproduce the R rasterize function in python to streamline my code and am having issues with summing multiple points in the raster. Essentially I want to sum the value of my variable for every point in the grid I create. However currently it only appears to be returning the value of the first point in the grid it sees.



    import rasterio
    import geopandas as gpd

    def create_raster_defined_res(geodataset, output, out_var, resolution):
    res = (resolution, resolution)
    bounds = geodataset.total_bounds
    kwargs = {
    'count': 1,
    'crs': geodataset.crs['init'],
    'bounds': bounds,
    'width': max(int(ceil((bounds[2] - bounds[0]) / float(res[0]))), 1),
    'height': max(int(ceil((bounds[3] - bounds[1]) / float(res[1]))), 1),
    'affine': Affine(res[0], 0, bounds[0], 0, -res[1], bounds[3]),
    'transform': (bounds[0], res[0], 0, bounds[3], 0, -res[1]),
    'compress': 'lzw',
    'driver': u'GTiff',
    'dtype': 'float64',
    #'nodata': -1e+308
    }

    with rasterio.open(output, 'w', **kwargs) as out:
    out_arr = np.empty([kwargs['height'],kwargs['width']])

    # this is where we create a generator of geom, value pairs to use in rasterizing
    shapes = ((geom,value) for geom, value in zip(geodataset['geometry'], geodataset[out_var]))

    burned = rasterize(shapes=shapes, fill=0, out=out_arr, transform=kwargs['affine'])
    out.write_band(1, burned)

    create_raster_defined_res(geopandas_dataset, output_tiff, output_var, 2500)


    Is there a way to add a parameter to sum the value of all the points that enter into the grid or tell it to add instead of just taking the value of the first point?










    share|improve this question

























      0












      0








      0








      I'm trying to reproduce the R rasterize function in python to streamline my code and am having issues with summing multiple points in the raster. Essentially I want to sum the value of my variable for every point in the grid I create. However currently it only appears to be returning the value of the first point in the grid it sees.



      import rasterio
      import geopandas as gpd

      def create_raster_defined_res(geodataset, output, out_var, resolution):
      res = (resolution, resolution)
      bounds = geodataset.total_bounds
      kwargs = {
      'count': 1,
      'crs': geodataset.crs['init'],
      'bounds': bounds,
      'width': max(int(ceil((bounds[2] - bounds[0]) / float(res[0]))), 1),
      'height': max(int(ceil((bounds[3] - bounds[1]) / float(res[1]))), 1),
      'affine': Affine(res[0], 0, bounds[0], 0, -res[1], bounds[3]),
      'transform': (bounds[0], res[0], 0, bounds[3], 0, -res[1]),
      'compress': 'lzw',
      'driver': u'GTiff',
      'dtype': 'float64',
      #'nodata': -1e+308
      }

      with rasterio.open(output, 'w', **kwargs) as out:
      out_arr = np.empty([kwargs['height'],kwargs['width']])

      # this is where we create a generator of geom, value pairs to use in rasterizing
      shapes = ((geom,value) for geom, value in zip(geodataset['geometry'], geodataset[out_var]))

      burned = rasterize(shapes=shapes, fill=0, out=out_arr, transform=kwargs['affine'])
      out.write_band(1, burned)

      create_raster_defined_res(geopandas_dataset, output_tiff, output_var, 2500)


      Is there a way to add a parameter to sum the value of all the points that enter into the grid or tell it to add instead of just taking the value of the first point?










      share|improve this question














      I'm trying to reproduce the R rasterize function in python to streamline my code and am having issues with summing multiple points in the raster. Essentially I want to sum the value of my variable for every point in the grid I create. However currently it only appears to be returning the value of the first point in the grid it sees.



      import rasterio
      import geopandas as gpd

      def create_raster_defined_res(geodataset, output, out_var, resolution):
      res = (resolution, resolution)
      bounds = geodataset.total_bounds
      kwargs = {
      'count': 1,
      'crs': geodataset.crs['init'],
      'bounds': bounds,
      'width': max(int(ceil((bounds[2] - bounds[0]) / float(res[0]))), 1),
      'height': max(int(ceil((bounds[3] - bounds[1]) / float(res[1]))), 1),
      'affine': Affine(res[0], 0, bounds[0], 0, -res[1], bounds[3]),
      'transform': (bounds[0], res[0], 0, bounds[3], 0, -res[1]),
      'compress': 'lzw',
      'driver': u'GTiff',
      'dtype': 'float64',
      #'nodata': -1e+308
      }

      with rasterio.open(output, 'w', **kwargs) as out:
      out_arr = np.empty([kwargs['height'],kwargs['width']])

      # this is where we create a generator of geom, value pairs to use in rasterizing
      shapes = ((geom,value) for geom, value in zip(geodataset['geometry'], geodataset[out_var]))

      burned = rasterize(shapes=shapes, fill=0, out=out_arr, transform=kwargs['affine'])
      out.write_band(1, burned)

      create_raster_defined_res(geopandas_dataset, output_tiff, output_var, 2500)


      Is there a way to add a parameter to sum the value of all the points that enter into the grid or tell it to add instead of just taking the value of the first point?







      python rasterization






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 20 '18 at 13:55









      DarknessFallsDarknessFalls

      11




      11






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Hej! Did you find a solution for your problem?? I'm having kind of the same here. :)






          share|improve this answer








          New contributor




          Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "79"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f290110%2fpython-rasterize-sum-variable%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Hej! Did you find a solution for your problem?? I'm having kind of the same here. :)






            share|improve this answer








            New contributor




            Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

























              0














              Hej! Did you find a solution for your problem?? I'm having kind of the same here. :)






              share|improve this answer








              New contributor




              Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.























                0












                0








                0







                Hej! Did you find a solution for your problem?? I'm having kind of the same here. :)






                share|improve this answer








                New contributor




                Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.










                Hej! Did you find a solution for your problem?? I'm having kind of the same here. :)







                share|improve this answer








                New contributor




                Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer






                New contributor




                Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 13 mins ago









                Christin AbelChristin Abel

                1




                1




                New contributor




                Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                Christin Abel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f290110%2fpython-rasterize-sum-variable%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Щит и меч (фильм) Содержание Названия серий | Сюжет |...

                    Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

                    Meter-Bus Содержание Параметры шины | Стандартизация |...